예제 #1
0
파일: Main.cs 프로젝트: sferryUL/dB_Manager
        private void btnDefOpen_Click(object sender, EventArgs e)
        {
            if (txtDefFile.Text == "")
            {
                MsgBox.Err("A filename is required!");
                return;
            }

            try
            {
                xlApp = new XL.Application();
                xlWB  = xlApp.Workbooks.Open(txtDefFile.Text);
                xlWS  = xlWB.Worksheets[1];
                xlRng = xlWS.UsedRange;
            }
            catch (Exception ex)
            {
                MsgBox.Err("Error opening file!\n" + ex.Message, "File Error");
                return;
            }

            DrvDefData = new List <Drv_List_Data>();

            string tmpStat = statMain_lblStat.Text;

            statMain_lblStat.Text  = "Reading Drive Master Parameter List";
            statMain_prgIO.Value   = 0;
            statMain_prgIO.Visible = true;
            dgvDefVal.Rows.Clear();
            for (int i = 2; i < xlRng.Rows.Count; i++)
            {
                Drv_List_Data dat = new Drv_List_Data();

                dat.Index = i;

                if (xlRng.Cells[i, 2] != null && xlRng.Cells[i, 2].Value2 != null)
                {
                    dat.RegAddress = Convert.ToInt32(xlRng.Cells[i, 2].Value2);
                }
                else
                {
                    dat.RegAddress = 0;
                }

                if (xlRng.Cells[i, 3] != null && xlRng.Cells[i, 3].Value2 != null)
                {
                    dat.ParamNum = xlRng.Cells[i, 3].Value2.ToString();
                }
                else
                {
                    dat.ParamNum = "0";
                }

                if (xlRng.Cells[i, 4] != null && xlRng.Cells[i, 4].Value2 != null)
                {
                    dat.ParamName = xlRng.Cells[i, 4].Value2.ToString();
                }
                else
                {
                    dat.ParamName = "0";
                }

                if (xlRng.Cells[i, 5] != null && xlRng.Cells[i, 5].Value != null)
                {
                    dat.DefVal = Convert.ToInt32(xlRng.Cells[i, 5].Value2);
                }
                else
                {
                    dat.DefVal = 0;
                }

                if (xlRng.Cells[i, 6] != null && xlRng.Cells[i, 5].Value2 != null)
                {
                    dat.Multiplier = Convert.ToInt32(xlRng.Cells[i, 5].Value2);
                }
                else
                {
                    dat.Multiplier = 1;
                }

                if (xlRng.Cells[i, 7] != null && xlRng.Cells[i, 6].Value2 != null)
                {
                    dat.NumBase = Convert.ToInt32(xlRng.Cells[i, 6].Value2);
                }
                else
                {
                    dat.NumBase = 10;
                }

                if (xlRng.Cells[i, 8] != null && xlRng.Cells[i, 7].Value2 != null)
                {
                    dat.Units = xlRng.Cells[i, 7].Value2.ToString();
                }
                else
                {
                    dat.Units = "";
                }

                dgvDefVal.Rows.Add(new string[]
                {
                    ("0x" + dat.RegAddress.ToString("X4")),
                    dat.ParamNum,
                    dat.ParamName,
                    dat.DefVal.ToString()
                });

                DrvDefData.Add(dat);

                Single percent = (float)i / xlRng.Rows.Count;
                percent *= 100;
                int val = (int)percent;
                statMain_prgIO.Value = val;
            }

            xlFunc.xlClose(ref xlApp, ref xlWB, ref xlWS, ref xlRng);
            statMain_lblStat.Text  = tmpStat;
            statMain_prgIO.Visible = false;

            GetDriveList();
            GetTableList(cmbDefTblList);
            cmbDefTblList.SelectedIndex = 2;

            // Try to select the correct drive
            string drive     = DefFileSafe.Substring(0, DefFileSafe.IndexOf('_'));
            int    idx_drive = -1;

            for (int i = 0; i < DrvInfo.Count; i++)
            {
                if (drive.Equals(DrvInfo[i].PartNum))
                {
                    idx_drive = i;
                    break;
                }
            }

            if (idx_drive >= 0)
            {
                cmbDefDrive.SelectedIndex = idx_drive;
            }

            // Try to select the correct duty rating of the drive
            int    idx_duty = -1;
            string duty     = DefFileSafe.Substring(DefFileSafe.IndexOf('_') + 1, 2);

            switch (duty)
            {
            case "HD":
                idx_duty = 0;
                break;

            case "ND":
                idx_duty = 1;
                break;
            }

            if (idx_duty >= 0)
            {
                cmbDefDuty.SelectedIndex = idx_duty;
            }

            // if both drive ID and duty rating have been determined setup the column name
            if ((idx_duty >= 0) && (idx_drive >= 0))
            {
                btnDefColCfg_Click(sender, e);
            }

            grpDefTools.Enabled = true;
        } // btnDefOpen_Click
예제 #2
0
파일: Main.cs 프로젝트: sferryUL/dB_Manager
        private void btnListFileOpen_Click(object sender, EventArgs e)
        {
            if (txtListFile.Text == "")
            {
                MsgBox.Err("A filename is required!");
                return;
            }

            try
            {
                xlApp = new XL.Application();
                xlWB  = xlApp.Workbooks.Open(ListFileFull);
                xlWS  = xlWB.Worksheets[1];
                xlRng = xlWS.UsedRange;
            }
            catch (Exception ex)
            {
                MsgBox.Err("Error opening file!\n" + ex.Message, "File Error");
                return;
            }

            DrvParmData = new List <Drv_List_Data>();

            string tmpStat = statMain_lblStat.Text;

            statMain_lblStat.Text  = "Reading Drive Master Parameter List";
            statMain_prgIO.Value   = 0;
            statMain_prgIO.Visible = true;
            dgvList.Rows.Clear();
            for (int i = 2; i < xlRng.Rows.Count; i++)
            {
                Drv_List_Data dat = new Drv_List_Data();

                dat.Index = i;

                if (xlRng.Cells[i, 2] != null && xlRng.Cells[i, 2].Value2 != null)
                {
                    dat.RegAddress = Convert.ToInt32(xlRng.Cells[i, 2].Value2);
                }
                else
                {
                    dat.RegAddress = 0;
                }

                if (xlRng.Cells[i, 3] != null && xlRng.Cells[i, 3].Value2 != null)
                {
                    dat.ParamNum = xlRng.Cells[i, 3].Value2.ToString();
                }
                else
                {
                    dat.ParamNum = "0";
                }

                if (xlRng.Cells[i, 4] != null && xlRng.Cells[i, 4].Value2 != null)
                {
                    dat.ParamName = xlRng.Cells[i, 4].Value2.ToString();
                }
                else
                {
                    dat.ParamName = "0";
                }

                if (xlRng.Cells[i, 5] != null && xlRng.Cells[i, 5].Value2 != null)
                {
                    dat.Multiplier = Convert.ToInt32(xlRng.Cells[i, 5].Value2);
                }
                else
                {
                    dat.Multiplier = 1;
                }

                if (xlRng.Cells[i, 6] != null && xlRng.Cells[i, 6].Value2 != null)
                {
                    dat.NumBase = Convert.ToInt32(xlRng.Cells[i, 6].Value2);
                }
                else
                {
                    dat.NumBase = 10;
                }

                if (xlRng.Cells[i, 7] != null && xlRng.Cells[i, 7].Value2 != null)
                {
                    dat.Units = xlRng.Cells[i, 7].Value2.ToString();
                }
                else
                {
                    dat.Units = "";
                }


                dgvList.Rows.Add(new string[]
                {
                    ("0x" + dat.RegAddress.ToString("X4")),
                    dat.ParamNum,
                    dat.ParamName,
                    dat.Multiplier.ToString(),
                    dat.NumBase.ToString(),
                    dat.Units
                });


                DrvParmData.Add(dat);

                Single percent = (float)i / xlRng.Rows.Count;
                percent *= 100;
                int val = (int)percent;
                statMain_prgIO.Value = val;
            }
            xlFunc.xlClose(ref xlApp, ref xlWB, ref xlWS, ref xlRng);


            statMain_lblStat.Text  = tmpStat;
            statMain_prgIO.Visible = false;
            GetTableList(cmbListTblSel);
            cmbListTblSel.Enabled = true;
            btnListImp.Enabled    = true;
        }