Exemplo n.º 1
0
        // ЗАПЧАСТЬ - ДОБАВИТЬ - СОХРАНИТЬ
        public spare SpareCreate(string Name, string Code, string CodeShatem, int QDemand, int GroupID, int BrandID, string UnitName, string Description)
        {
            DataAccess da = new DataAccess();
            spare sp = new spare();
            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;
            spare s = da.SpareCreate(sp, BrandID, GroupID, UnitName);

            SpareContainer.Instance.Update(s.id);

            if (SpareContainer.Instance.Spares.Where(
                    i => i.BrandID == BrandID && i.GroupID == GroupID).Count() == 1)
            {
                da.SpareGroupCreate(GroupID, BrandID);
            }
            return s;
        }
Exemplo n.º 2
0
        //private delegate void UpdateProgressBarDelegate(System.Windows.DependencyProperty dp, Object value);
        public static int getSpares(string FilePath)
        {
            List<spare> items = new List<spare>();

            // Объявляем и забиваем файл в документ
            XmlDocument xd = new XmlDocument();
            FileStream fs = new FileStream(FilePath, FileMode.Open);
            xd.Load(fs);
            DataAccess da = new DataAccess();

            XmlNodeList list = xd.GetElementsByTagName("Row"); // Создаем и заполняем лист по тегу "user"

            LoadingWindowView v = new LoadingWindowView();
            v._ProgressBar.Minimum = 0;
            v._ProgressBar.Maximum = list.Count;
            v._ProgressBar.Value = list.Count / 2;

            //object value = 0;
            //Сохраняем значение ProgressBar
            //Создаем новый экземпляр делегата для ProgressBar
            // который показывает на метод ProgressBar.SetValue
            //UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(v._ProgressBar.SetValue);
            v.Show();
            string Errors = "";
            for (int i = 1; i < list.Count; i++)
            {
                try
                {
                    spare b = new spare();
                    b.code1C = list[i].ChildNodes[0].InnerText;
                    if (!da.ExistCode1C(b.code1C))
                    {
                        b.codeShatem = list[i].ChildNodes[1].InnerText;
                        b.name = list[i].ChildNodes[2].InnerText;
                        string BrandCode1C = list[i].ChildNodes[3].InnerText;
                        string GroupCode1C = list[i].ChildNodes[4].InnerText;
                        da.SpareCreate(b, BrandCode1C, GroupCode1C);
                    }
                }
                catch (Exception qwe)
                {
                    Errors += qwe.Message;
                }
            }

            // Закрываем поток
            fs.Close();
            v.Close();
            return items.Count;
        }
Exemplo n.º 3
0
        private void ImportSparesFromCSV()
        {
            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 GrandParentGroupName = RawRecord[0];
                            string ParentGroupName = RawRecord[1];
                            string BrandName = RawRecord[2];
                            string SpareCode = RawRecord[3];
                            string SpareName = RawRecord[4];
                            string CarModels = RawRecord[5];

                            if (!da.SpareExist(SpareCode, SpareName))
                            {
                                Console.WriteLine(GlobalCnt.ToString() + ": " + SpareName + " - " + SpareCode + " - creating");
                                da.SpareCreate(GrandParentGroupName, ParentGroupName, BrandName, SpareCode, SpareName, CarModels);
                            }
                            else
                            {
                                Console.WriteLine(GlobalCnt.ToString() + ": " + SpareName + " - " + SpareCode + " already exist");
                            }
                            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();
        }
Exemplo n.º 4
0
        private void BackgroundCreate_DoWork(object sender, DoWorkEventArgs e)
        {
            DataAccess da = new DataAccess();
            spare sp = new spare();
            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;
            spare s = da.SpareCreate(sp, SpareUpdateBrandID, SpareUpdateGroupID, SpareUpdateUnitID);
            SpareContainer.Instance.Update(s.id);

            if (SpareContainer.Instance.Spares.Where(i => i.BrandID == SpareUpdateBrandID && i.GroupID == SpareUpdateGroupID).Count() == 1)
            {
                if (s.brand == null)
                    s.brandReference.Load();
                da.SpareGroupCreate(SpareUpdateGroupID, s.brand.name);
                ReloadGroups = true;
            }
        }