Exemplo n.º 1
0
        //    public Add commandAdd
        //   { set; get; }
        public SetupDialog(ZDStruct zd)
        {
            _object = zd;
            InitializeComponent();
            model            = new SetupTableModel(zd);
            this.DataContext = model;
            objectType       = typeof(ZDStruct);
            Title            = "Настройка задвижки";

            //       SetupBindings();
        }
Exemplo n.º 2
0
        /// <summary>
        /// чтение настроек задвижек
        /// </summary>
        /// <param name="conn"></param>
        private static void ReadZD(OleDbConnection conn)
        {
            OleDbCommand cmd = new OleDbCommand
            {
                Connection = conn
            };

            // Get all Sheets in Excel File
            DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);


            //======================================================================= чтение таблицы DI задвижек =====================================
            string sheetName = "";

            foreach (DataRow dr in dtSheet.Rows)
            {
                sheetName = dr["TABLE_NAME"].ToString();
                if (sheetName.Contains("DI задвижек"))
                {
                    //LogViewModel.WriteLine("Таблица задвижек найдена, чтение данных...");
                    LogWriter.AppendLog("Таблица задвижек найдена, чтение данных...");
                    break;
                }
            }
            // Get all rows from the Sheet
            cmd.CommandText = "SELECT * FROM [" + sheetName + "]";

            DataTable dt = new DataTable
            {
                TableName = sheetName
            };

            OleDbDataAdapter da = new OleDbDataAdapter(cmd);

            ZDTableViewModel.ZDs.Clear();
            da.Fill(dt);
            object[] zdparams = new object[7];
            //=================
            for (int i = 0; i < dt.Rows.Count / 8; i++)
            {
                int      rowindex = i * 8 + 4;
                ZDStruct zd;
                if (dt.Rows[rowindex].ItemArray[0] is DBNull) //название задвижки пустое, прекращаем чтение
                {
                    break;
                }
                else
                {
                    zd = new ZDStruct
                    {
                        Description = (string)dt.Rows[rowindex].ItemArray[0]
                    };
                    if (zd.Description.Length < 2)
                    {
                        break;
                    }
                    zd.En = true;
                    ZDTableViewModel.ZDs.Add(zd);
                }

                for (int j = 0; j < 8; j++)
                {
                    object zdParam = dt.Rows[rowindex + j].ItemArray[8];
                    int    iParam  = 0;

                    if (zdParam is string)
                    {
                        iParam = int.Parse((string)(zdParam));
                    }
                    else if (zdParam is double)
                    {
                        iParam = (int)((double)zdParam);
                    }


                    if (iParam == 0)
                    {
                        continue;
                    }

                    switch (j)
                    {
                    case 0: zd.OKCindxArrDI = DIStruct.FindByNsign(iParam + 1000); break;    //КВО

                    case 1: zd.CKCindxArrDI = DIStruct.FindByNsign(iParam + 1000); break;    //КВЗ

                    case 2: zd.ODCindxArrDI = DIStruct.FindByNsign(iParam + 1000); break;    //МПО

                    case 3: zd.CDCindxArrDI = DIStruct.FindByNsign(iParam + 1000); break;    //МПЗ

                    case 4: zd.DCindxArrDI = DIStruct.FindByNsign(iParam + 1000); break;     //Дист

                    case 5: zd.VoltindxArrDI = DIStruct.FindByNsign(iParam + 1000); break;   //напряж

                    case 6: zd.MCindxArrDI = DIStruct.FindByNsign(iParam + 1000); break;     //муфта

                    case 7: zd.OPCindxArrDI = DIStruct.FindByNsign(iParam + 1000); break;    //авария
                    }
                }
            }


            foreach (DataRow dr in dtSheet.Rows)
            {
                sheetName = dr["TABLE_NAME"].ToString();
                if (sheetName.Contains("DO задвижек"))
                {
                    //LogViewModel.WriteLine("Таблица DO задвижек найдена, чтение данных...");
                    LogWriter.AppendLog("Таблица DO задвижек найдена, чтение данных...");
                    break;
                }
            }

            // Get all rows from the Sheet
            cmd.CommandText = "SELECT * FROM [" + sheetName + "]";

            dt = new DataTable
            {
                TableName = sheetName
            };

            //OleDbDataAdapter da = new OleDbDataAdapter(cmd);

            da.Fill(dt);

            for (int i = 0; i < ZDTableViewModel.ZDs.Count; i++)
            {
                int rowindex = i * 4 + 4;

                for (int j = 0; j < 4; j++)
                {
                    object zdParam = dt.Rows[rowindex + j].ItemArray[5];
                    int    iParam  = 0;

                    if (zdParam is string)
                    {
                        iParam = int.Parse((string)(zdParam));
                    }
                    else if (zdParam is double)
                    {
                        iParam = (int)((double)zdParam);
                    }


                    if (iParam == 0)
                    {
                        continue;
                    }

                    switch (j)
                    {
                    case 0: ZDTableViewModel.ZDs[i].DOBindxArrDO = DOStruct.FindByNsign(iParam + 4000); break;     //открыть

                    case 1: ZDTableViewModel.ZDs[i].DKBindxArrDO = DOStruct.FindByNsign(iParam + 4000); break;     //закрыть

                    case 2: ZDTableViewModel.ZDs[i].DCBindxArrDO = DOStruct.FindByNsign(iParam + 4000); break;     //стоп

                    case 3: ZDTableViewModel.ZDs[i].DCBZindxArrDO = DOStruct.FindByNsign(iParam + 4000); break;    //стоп закрытия
                    }
                }
            }
        }//readzd