using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WardMapMigration.Utilities
{
class MissionBedRoom6
{
public void ReadHXDbToControl(string userId)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
List<M_LOCAL_WARDMAP_CONTROL> controlList = new List<M_LOCAL_WARDMAP_CONTROL>();
List<M_LOCAL_WARDMAP_CONTROL> hxList = new List<M_LOCAL_WARDMAP_CONTROL>();
List<M_LOCAL_WARDMAP_CONTROL> hxList2 = new List<M_LOCAL_WARDMAP_CONTROL>();
//接続HXデータベース読み出しテーブルM_LOCAL_WARDMAP_CONTROOLデータ:
string strconn = "Persist Security Info=False;User ID=sa;Password=zzr1100!;Data Source=10.167.21.78;Initial Catalog=HXDB;MultipleActiveResultSets=true";
SqlConnection sqlConn = new SqlConnection(strconn);
sqlConn.Open();
String sqlStr = "select HospitalCode,WardCode,ControlID,XamlControlType,ControlLeftProperty,ControlTopProperty,ControlHeightProperty,ControlWidthProperty,ControlProperty from chart.M_LOCAL_WARDMAP_CONTROL";
SqlCommand sqlComm = new SqlCommand(sqlStr, sqlConn);
SqlDataReader sqlReader = sqlComm.ExecuteReader();
CreateExcelControl cec = new CreateExcelControl();
//各方位に必要な乗算数
double leftNum = 0.096797153;
double topNum = 0.068466258;
double heighNum = 0.068466258;
double widthNum = 0.096797153;
string TB_left;
string TB_top;
string TB_width;
string TB_height;
string TB_Name;
bool flag_1 = false;
bool flag_2 = false;
bool flag_3 = false;
List<string> leftList = new List<string>();
List<string> topList = new List<string>();
List<string> widthList = new List<string>();
List<string> heightList = new List<string>();
List<string> nameList = new List<string>();
//天窓から飛び出してファイルパスを選択
string foldPath1 = @"C:\egmain-ex\Data\Xtml_S\03E.xtm";
dialog.Description = "ファイルのパスを選択してください";
string WcValue = foldPath1.Substring(25, 3);
//天窓から飛び出してファイルパスを選択
string foldPath = string.Empty;
dialog.Description = "ファイルのパスを選択してください";
if (dialog.ShowDialog() == DialogResult.OK)
{
foldPath = dialog.SelectedPath;
}
if (foldPath == "" || foldPath == null)
{
MessageBox.Show("Error:ファイルパスが選択されていません!");
if (dialog.ShowDialog() == DialogResult.OK)
{
foldPath = dialog.SelectedPath;
}
}
while (sqlReader.Read())
{
M_LOCAL_WARDMAP_CONTROL mlwc = new M_LOCAL_WARDMAP_CONTROL();
mlwc.HospitalCode = sqlReader["HospitalCode"].ToString();
mlwc.ControlID = sqlReader["ControlID"].ToString();
mlwc.WardCode = sqlReader["WardCode"].ToString();
mlwc.XamlControlType = sqlReader["XamlControlType"].ToString();
mlwc.ControlProperty = sqlReader["ControlProperty"].ToString();
mlwc.CreateUserID = userId;
mlwc.UpdateUserID = userId;
controlList.Add(mlwc);
}
sqlConn.Close();
//cec.insertToSheetPartsAttributes(controlList, foldPath + @"\MasterUpdateTool.xlsx");
String[] stringlines = File.ReadAllLines(@"C:\egmain-ex\Data\Xtml_S\03E.xtm");
M_LOCAL_WARDMAP_CONTROL hxMlwc = null;
foreach (string node in stringlines)
{
//M_LOCAL_WARDMAP_CONTROL mlwc = new M_LOCAL_WARDMAP_CONTROL();
//プログラム制御スイッチの定義
if (node.Contains("<COMMANDBUTTON NAME=\"") || flag_1)
{
if (!flag_1)
{
hxMlwc = new M_LOCAL_WARDMAP_CONTROL();
}
if (node.Contains("<COMMANDBUTTON NAME=\""))
{
TB_Name = node;
TB_Name = TB_Name.Substring(0, node.Length);
TB_Name = TB_Name.Replace("<COMMANDBUTTON NAME=\"", "");
TB_Name = TB_Name.Replace("\"", "");
TB_Name = "R" + TB_Name;
hxMlwc.ControlID = TB_Name;
hxList.Add(hxMlwc);
flag_1 = true;
}
else if (node.Contains("LEFT"))
{
TB_left = node;
TB_left = TB_left.Substring(0, node.Length);//LEFT="2700"
TB_left = TB_left.Replace("LEFT=\"", "");
TB_left = TB_left.Replace("\"", "");
int tleft = Convert.ToInt32(TB_left);
double dleft = tleft * leftNum;
double inLeft = Math.Round(dleft);
string leftResult = Convert.ToString(inLeft);
hxMlwc.ControlLeftProperty = leftResult;
hxList.Add(hxMlwc);
flag_1 = true;
}
else if (node.Contains("TOP"))
{
TB_top = node;
TB_top = TB_top.Substring(0, node.Length);
TB_top = TB_top.Replace("TOP=\"", "");
TB_top = TB_top.Replace("\"", "");
int ttop = Convert.ToInt32(TB_top);
double dtop = ttop * topNum;
double inTop = Math.Round(dtop);
string topResult = Convert.ToString(inTop);
hxMlwc.ControlTopProperty = topResult;
hxList.Add(hxMlwc);
flag_1 = true;
}
else if (node.Contains("WIDTH"))
{
TB_width = node;
TB_width = TB_width.Substring(0, node.Length);
TB_width = TB_width.Replace("WIDTH=\"", "");
TB_width = TB_width.Replace("\"", "");
int twidth = Convert.ToInt32(TB_width);
double dwidth = twidth * widthNum;
double inwidth = Math.Round(dwidth);
string widthResult = Convert.ToString(inwidth);
hxMlwc.ControlWidthProperty = widthResult;
hxList.Add(hxMlwc);
flag_1 = true;
}
else if (node.Contains("HEIGHT"))
{
TB_height = node;
TB_height = TB_height.Substring(0, node.Length);
TB_height = TB_height.Replace("HEIGHT=\"", "");
TB_height = TB_height.Replace("\"", "");
int theight = Convert.ToInt32(TB_height);
double dheight = theight * heighNum;
double inheight = Math.Round(dheight);
string heigthResult = Convert.ToString(inheight);
hxMlwc.ControlHeightProperty = heigthResult;
hxList.Add(hxMlwc);
flag_1 = true;
}
else if (node.Contains("\">"))
{
flag_1 = false;
}
}
else if (node.Contains("<LABEL NAME=\"") || flag_2)
{
if (!flag_2)
{
hxMlwc = new M_LOCAL_WARDMAP_CONTROL();
}
if (node.Contains("<LABEL NAME=\""))
{
TB_Name = node;
TB_Name = TB_Name.Substring(0, node.Length);
TB_Name = TB_Name.Replace("<LABEL NAME=\"", "");
TB_Name = TB_Name.Replace("\"", "");
TB_Name = "R" + TB_Name;
hxMlwc.ControlID = TB_Name;
hxList2.Add(hxMlwc);
flag_2 = true;
}
if (node.Contains("LEFT"))
{
TB_left = node;
TB_left = TB_left.Substring(0, node.Length);//LEFT="2700"
TB_left = TB_left.Replace("LEFT=\"", "");
TB_left = TB_left.Replace("\"", "");
int tleft = Convert.ToInt32(TB_left);
double dleft = tleft * leftNum;
double inLeft = Math.Round(dleft);
string leftResult = Convert.ToString(inLeft);
//leftList.Add(leftResult);
hxMlwc.ControlLeftProperty = leftResult;
hxList2.Add(hxMlwc);
flag_2 = true;
}
if (node.Contains("TOP"))
{
TB_top = node;
TB_top = TB_top.Substring(0, node.Length);
TB_top = TB_top.Replace("TOP=\"", "");
TB_top = TB_top.Replace("\"", "");
int ttop = Convert.ToInt32(TB_top);
double dtop = ttop * topNum;
double inTop = Math.Round(dtop);
string topResult = Convert.ToString(inTop);
hxMlwc.ControlTopProperty = topResult;
hxList2.Add(hxMlwc);
flag_2 = true;
//topList.Add(topResult);
}
if (node.Contains("WIDTH"))
{
TB_width = node;
TB_width = TB_width.Substring(0, node.Length);
TB_width = TB_width.Replace("WIDTH=\"", "");
TB_width = TB_width.Replace("\"", "");
int twidth = Convert.ToInt32(TB_width);
double dwidth = twidth * widthNum;
double inwidth = Math.Round(dwidth);
string widthResult = Convert.ToString(inwidth);
hxMlwc.ControlWidthProperty = widthResult;
hxList2.Add(hxMlwc);
flag_2 = true;
}
if (node.Contains("HEIGHT"))
{
TB_height = node;
TB_height = TB_height.Substring(0, node.Length);
TB_height = TB_height.Replace("HEIGHT=\"", "");
TB_height = TB_height.Replace("\"", "");
int theight = Convert.ToInt32(TB_height);
double dheight = theight * heighNum;
double inheight = Math.Round(dheight);
string heigthResult = Convert.ToString(inheight);
hxMlwc.ControlHeightProperty = heigthResult;
hxList2.Add(hxMlwc);
flag_2 = true;
//heightList.Add(heigthResult);
}
if (node.Contains("\">"))
{
flag_2 = false;
}
}
}
foreach (M_LOCAL_WARDMAP_CONTROL attribute in controlList)
{
foreach (M_LOCAL_WARDMAP_CONTROL hxattribute in hxList)
{
string Cid = hxattribute.ControlID.Trim();//HX的 R9999
string wccValue = WcValue + Cid;//03ER9999
if (attribute.WardCode.Trim() == WcValue && wccValue == (attribute.WardCode + attribute.ControlID.Trim()))
{
attribute.WardCode = WcValue;
attribute.ControlID = Cid;
attribute.XamlControlType = attribute.XamlControlType;
attribute.ControlLeftProperty = hxattribute.ControlLeftProperty;
attribute.ControlTopProperty = hxattribute.ControlTopProperty;
attribute.ControlWidthProperty = hxattribute.ControlWidthProperty;
attribute.ControlHeightProperty = hxattribute.ControlHeightProperty;
break;
}
}
foreach (M_LOCAL_WARDMAP_CONTROL hxattribute2 in hxList2)
{
string Cid = hxattribute2.ControlID.Trim();//HX的 R999901
string wccValue = WcValue + Cid;//03ER999901
if (attribute.WardCode.Trim() == WcValue && wccValue == (attribute.WardCode + attribute.ControlID.Trim()) )
{
attribute.ControlID = Cid;
attribute.XamlControlType = attribute.XamlControlType;
attribute.ControlLeftProperty = hxattribute2.ControlLeftProperty;
attribute.ControlTopProperty = hxattribute2.ControlTopProperty;
attribute.ControlWidthProperty = hxattribute2.ControlWidthProperty;
attribute.ControlHeightProperty = hxattribute2.ControlHeightProperty;
break;
}
}
}
cec.insertToSheetPartsAttributes(controlList);
cec.SaveFile(foldPath + @"\MasterUpdateTool.xlsx");
cec.Dispose();
}
}
}