예제 #1
0
        public async void saveDB(ObservableCollection <bomm> db)
        {
            try
            {
                using (var ctx = new dbcontext())
                {
                    foreach (var item in db)
                    {
                        bomm b = new bomm();
                        b.bom_level            = item.bom_level;
                        b.Parent_Part_Number   = item.Parent_Part_Number;
                        b.Part_Number          = item.Part_Number;
                        b.Part_Name            = item.Part_Name;
                        b.Revision             = item.Revision;
                        b.Quantit              = item.Quantit;
                        b.Unit_of_measure      = item.Unit_of_measure;
                        b.Procurement_Type     = item.Procurement_Type;
                        b.Reference_Designatos = item.Reference_Designatos;
                        b.BOM_Notes            = item.BOM_Notes;

                        ctx.bomm.Add(b);
                    }
                    ctx.SaveChanges();
                }
            }
            catch (Exception e)
            {
                await MainWindow.Instance.ShowMessageAsync("Error", e.Message);
            }
        }
예제 #2
0
        //method for get content of excel file
        public ObservableCollection <bomm> getContent_EXCEL()
        {
            //list for return
            ObservableCollection <bomm> db = new ObservableCollection <bomm>();

            //window for select excel file
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Excel Files (*.xls)|*.xls";
            openFileDialog.ShowDialog();

            string local = openFileDialog.FileName;

            if (local != String.Empty)
            {
                //using library for acess excel file
                var             application = new Excel.Application();
                Excel.Workbook  book        = application.Workbooks.Open(local);
                Excel.Worksheet mainSheet   = (Excel.Worksheet)book.Sheets[4];

                DataTable tb = new DataTable();

                //getting excel dates and saving in collection
                foreach (var item in mainSheet.UsedRange.Rows)
                {
                    Excel.Range   b   = item;
                    List <string> str = new List <string>();

                    foreach (Excel.Range cell in item.Columns)
                    {
                        str.Add(cell.Value + "");
                    }

                    bomm bomobj = new bomm();

                    bomobj.bom_level            = str[0];
                    bomobj.Part_Number          = str[2];
                    bomobj.Part_Name            = str[3];
                    bomobj.Revision             = str[4];
                    bomobj.Quantit              = str[5];
                    bomobj.Unit_of_measure      = str[6];
                    bomobj.Procurement_Type     = str[7];
                    bomobj.Reference_Designatos = str[8];
                    bomobj.BOM_Notes            = str[9];

                    str.Clear();
                    db.Add(bomobj);
                }
                db.RemoveAt(0);
                db.RemoveAt(0);
                db.RemoveAt(61);
                db.RemoveAt(61);

                //CleanUp
                application.ActiveWorkbook.Close();
                application.Quit();
                application.Dispose();
            }



            foreach (var item in db)
            {
                switch (item.bom_level)
                {
                case "0":
                    pivo0 = item.Part_Number;
                    break;

                case "1":
                    pivo1 = item.Part_Number;
                    break;

                case "2":
                    pivo2 = item.Part_Number;
                    break;

                case "3":
                    pivo3 = item.Part_Number;
                    break;

                case "4":
                    pivo4 = item.Part_Number;
                    break;

                default:
                {
                    break;
                }
                }

                switch (item.bom_level)
                {
                case "1":
                    item.Parent_Part_Number = pivo0;
                    break;

                case "2":
                    item.Parent_Part_Number = pivo1;
                    break;

                case "3":
                    item.Parent_Part_Number = pivo2;
                    break;

                case "4":
                    item.Parent_Part_Number = pivo3;
                    break;

                default:
                {
                    break;
                }
                }
            }
            return(db);
        }