Example #1
0
        public spare SpareEditInBackground(int SpareID, string Name, string Code, string CodeShatem, int QDemand, int GroupID, int BrandID, int UnitID, string Description)
        {
            DataAccess da = new DataAccess();
            spare sp = da.GetSpare(SpareID);
            sp.name = Name;
            sp.code = Code;
            sp.codeShatem = CodeShatem;
            sp.q_demand = QDemand;
            sp.q_demand_clear = QDemand;
            sp.q_rest = 0;
            sp.description = Description;
            if (sp.brand == null)
                sp.brandReference.Load();
            if (sp.spare_group == null)
                sp.spare_groupReference.Load();

            string OldBrandName = sp.BrandName;
            int OldBrandID = sp.brand.id;
            int OldGroupID = sp.spare_group.id;

            spare s = da.SpareEdit(sp, BrandID, GroupID, UnitID);
            return s;
        }
Example #2
0
        // ЗАПЧАСТЬ - РЕДАКТИРОВАТЬ - СОХРАНИТЬ
        public spare SpareEdit(int SpareID, string Name, string Code, string CodeShatem, int QDemand, int GroupID, int BrandID, int UnitID, string Description)
        {
            DataAccess da = new DataAccess();
            spare sp = da.GetSpare(SpareID);
            sp.name = Name;
            sp.code = Code;
            sp.codeShatem = CodeShatem;
            sp.q_demand = QDemand;
            sp.q_demand_clear = QDemand;
            sp.q_rest = 0;
            sp.description = Description;
            if (sp.brand == null)
                sp.brandReference.Load();
            if (sp.spare_group == null)
                sp.spare_groupReference.Load();

            string OldBrandName = sp.BrandName;
            int OldBrandID = sp.brand.id;
            int OldGroupID = sp.spare_group.id;

            spare s = da.SpareEdit(sp, BrandID, GroupID, UnitID);
            SpareContainer.Instance.Update(s.id);

            if (OldBrandID != BrandID || OldGroupID != GroupID)
            {
                if (SpareContainer.Instance.Spares.Where(i => i.BrandID == OldBrandID && i.GroupID == OldGroupID).Count() == 0)
                {
                    da.SpareGroupDelete(OldBrandID, OldGroupID);
                    mainWindowObj.LoadGroups(false);
                }
                if (SpareContainer.Instance.Spares.Where(i => i.BrandID == BrandID && i.GroupID == GroupID).Count() == 1)
                {
                    da.SpareGroupCreate(GroupID, BrandID);
                    mainWindowObj.LoadGroups(false);
                }
            }
            return s;
        }
Example #3
0
        private void ImportSpareCodesFromCSV()
        {
            ConsoleManager.Show();
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - started...");
            string FilePath = "";
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".csv"; // Default file extension

            //    dlg.Filter = "*.csv"; // Filter files by extension
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true)
            {
                DataAccess da = new DataAccess();

                // Open document
                FilePath = dlg.FileName;
                int counter = 0;
                int GlobalCnt = 0;
                using (CsvReader csvData = new CsvReader(FilePath))
                {
                    csvData.Settings.Delimiter = ';';
                    while (csvData.ReadRecord())
                    {
                        try
                        {
                            counter++;
                            GlobalCnt++;
                            string[] RawRecord = csvData.RawRecord.Split(';');
                            string CodeShatem = RawRecord[0];
                            string Code = RawRecord[1];

                            // delete chars after _
                            CodeShatem = CodeShatem.Split('_')[0];

                            if (da.SpareEdit(CodeShatem, Code))
                                Console.WriteLine(GlobalCnt.ToString() + ": " + CodeShatem + " ok!");
                            else
                                Console.WriteLine(GlobalCnt.ToString() + ": " + CodeShatem + " not found.");

                            if (counter > 1000)
                            {
                                counter = 0;
                                da = new DataAccess();
                                Console.WriteLine("Data access object refresh");
                            }
                        }
                        catch (Exception e1)
                        {
                            Console.WriteLine(GlobalCnt.ToString() + ": Exception failed: " + e1.Message);
                        }
                    }
                } // dispose of parser
            }
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - finished...");
            MessageBox.Show("Import finished!");
            Console.ReadLine();
            ConsoleManager.Hide();
            Application.Current.Shutdown();
        }
Example #4
0
        private void ImportSpareCodesFromCSV2()
        {
            ConsoleManager.Show();
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - started...");
            string FilePath = "";
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".csv"; // Default file extension

            //    dlg.Filter = "*.csv"; // Filter files by extension
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true)
            {
                DataAccess da = new DataAccess();

                // Open document
                FilePath = dlg.FileName;
                using (CsvReader csvData = new CsvReader(FilePath))
                {
                    csvData.Settings.Delimiter = ';';
                    while (csvData.ReadRecord())
                    {
                        da.SpareEdit(csvData.ReadToEnd());
                    }
                } // dispose of parser
            }
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " - finished...");
            MessageBox.Show("Import finished!");
            Console.ReadLine();
            ConsoleManager.Hide();
            Application.Current.Shutdown();
        }
Example #5
0
        private void BackgroundEdit_DoWork(object sender, DoWorkEventArgs e)
        {
            int SpareID = _spare.id;
            DataAccess da = new DataAccess();
            spare sp = da.GetSpare(SpareID);
            sp.name = SpareUpdateName;
            sp.code = SpareUpdateCode;
            sp.codeShatem = SpareUpdateCodeShatem;
            sp.q_demand = SpareUpdateQDemand;
            sp.q_demand_clear = SpareUpdateQDemand;
            sp.q_rest = 0;
            sp.description = SpareUpdateDescription;
            if (sp.brand == null)
                sp.brandReference.Load();
            if (sp.spare_group == null)
                sp.spare_groupReference.Load();

            string OldBrandName = sp.BrandName;
            int OldBrandID = sp.brand.id;
            int OldGroupID = sp.spare_group.id;

            spare s = da.SpareEdit(sp, SpareUpdateBrandID, SpareUpdateGroupID, SpareUpdateUnitID);
            SpareContainer.Instance.Update(s.id);

            if (OldBrandID != SpareUpdateBrandID || OldGroupID != SpareUpdateGroupID)
            {
                if (SpareContainer.Instance.Spares.Where(i => i.BrandID == OldBrandID && i.GroupID == OldGroupID).Count() == 0)
                {
                    da.SpareGroupDelete(OldBrandID, OldGroupID);
                    ReloadGroups = true;
                }
                if (SpareContainer.Instance.Spares.Where(i => i.BrandID == SpareUpdateBrandID && i.GroupID == SpareUpdateGroupID).Count() == 1)
                {
                    da.SpareGroupCreate(SpareUpdateGroupID, SpareUpdateBrandID);
                    ReloadGroups = true;
                }
            }
        }