获取每行属性内的值

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();

    }
    
  
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值