Ejemplo n.º 1
0
        public static zbs FindZBSByName(string zbsName)
        {
            zbs result = null;

            try
            {
                if (zbsList == null || zbsList.Count() == 0)
                {
                    if (LoadZBSList() == false)
                    {
                        ncLog.Error("FindZBSByName::Unable to load ZBS");
                        return(result);
                    }
                }

                result = zbsList.Where(x => x.nombre == zbsName).FirstOrDefault();

                if (result == null)
                {
                    result        = new zbs();
                    result.nombre = zbsName;
                }
            }

            catch (Exception exp)
            {
                ncLog.Exception("FindZBSByName::" + exp.Message);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private void btLoadZBS_Click(object sender, EventArgs e)
        {
            try
            {
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.Filter           = "Excel files (*.xls)|*.xls|All files (*.*)|*.*";
                    openFileDialog.FilterIndex      = 2;
                    openFileDialog.RestoreDirectory = true;

                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        //Get the path of specified file
                        string filePath = openFileDialog.FileName;
                        txtZBSPath.Text = filePath;

                        ncLog.Message("ExcelPath:" + filePath);

                        Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();

                        Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                                        Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                                        Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                                        Type.Missing, Type.Missing);

                        Worksheet sheet = (Worksheet)wb.Sheets["ZBS"];

                        Range excelRange = sheet.UsedRange;

                        int nRows = excelRange.Rows.Count;

                        ncLog.Message("Nº Rows:" + nRows);

                        foreach (Microsoft.Office.Interop.Excel.Range row in excelRange.Rows)
                        {
                            int rowNumber = row.Row;

                            if (rowNumber != 1) //Headers
                            {
                                string[] arrayAG = Util.GetRange("A" + rowNumber + ":G" + rowNumber + "", sheet);

                                zbs newZBS = new zbs(arrayAG);

                                if (!newZBS.IsOk())
                                {
                                    ncLog.Error("LoadZBS::Unable to create ZBS object row number:" + rowNumber);
                                    continue;
                                }

                                if (IctusDBManager.NewZBS(newZBS))
                                {
                                    ncLog.Message("LoadZBS::Inserted row number:" + rowNumber);
                                }
                                else
                                {
                                    ncLog.Message("LoadZBS::Unable to insert row number:" + rowNumber);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                ncLog.Exception("LoadZBS::" + exp.Message);
            }
        }