public SpareIncomeSmart(int IncID, string filename)
        {
            //try
            {
                InitializeComponent();
                DataAccess db = new DataAccess();
                Income = db.SpareIncomeGet(IncID);

                // readinf csv
                string[] source = File.ReadAllLines(filename, System.Text.Encoding.Default);
                int i = 0;
                foreach (string s in source)
                {
                    if (i != 0)
                    {
                        string[] fields = s.Split(';');

                        // 0 код_брэнд
                        string[] f1 = fields[0].Split('_');
                        string CodeShatem = f1[0];
                        string BrandName = f1[1];

                        // 1 количество
                        decimal Q = 0;
                        decimal.TryParse(fields[1], out Q);

                        // 2 код_брэнд_
                        string[] f2 = fields[2].Split('_');

                        // string CodeShatem = f1[0];
                        // string Brand = f1[1];
                        // string Code = f2[2];
                        // 3 Цена, доллар
                        decimal Pusd = 0;
                        string p = fields[3].Replace(',', '.');
                        decimal.TryParse(p, out Pusd);

                        // 4 Цена, евро
                        decimal Peuro = 0;
                        decimal.TryParse(fields[4], out Peuro);

                        // 5 группа
                        string ParentGroup = fields[5];

                        // 6 группа
                        string Group = fields[6];

                        // 7 группа
                        string name = fields[7];

                        // 8 единица измерения
                        string UnitName = fields[8];

                        // поиск запчасти по коду и брэнду
                        SpareView FoundSpare = null;
                        int searchFieldIndex = 2;   // код шате-м
                        List<SpareView> FoundList = SpareContainer.Instance.GetSparesStrict(searchFieldIndex, CodeShatem);
                        if (FoundList.Count == 0)
                        {
                            // если запчасть не найдена, предложить создать новую
                            string mess = "Товар с кодом [" + CodeShatem + "] не найден в базе.\n";
                            mess += "Название:  " + name + "\n";
                            mess += "Подгруппа: " + Group + "\n";
                            mess += "Группа:    " + ParentGroup + "\n";
                            mess += "Брэнд:     " + BrandName + "\n";
                            mess += "Создать новый?";
                            MessageBoxResult answer = MessageBox.Show(mess, "Импорт новой детали", MessageBoxButton.YesNo);
                            if (answer == MessageBoxResult.Yes)
                            {
                                // если создать новую, создать новую деталь
                                FoundSpare = Marvin.Instance.SpareCreateSilent(name, CodeShatem, Group, ParentGroup, BrandName, UnitName, "Импортировано");
                            }
                        }
                        else
                            if (FoundList.Count == 1)
                            {
                                FoundSpare = FoundList[0];
                            }
                            else
                            {
                                FoundList = FoundList.Where(x => x.BrandName == BrandName).ToList();

                                // если есть детали с одинаковым кодом, выбрать по брэнду (группе)
                                if (FoundList.Count == 1)
                                    FoundSpare = FoundList[0];
                            }
                        if (FoundSpare != null)
                        {
                            // добавить в список, подставиви количество и цену
                            OfferingAdd(FoundSpare.id, Q, Pusd, Group, ParentGroup);
                        }
                    }
                    i++;
                }
                LoadOfferings();
                Stage++;
                dgSpares.IsEnabled = true;
            }

            //catch(Exception e)
            //{
            //    MessageBox.Show("Ошибка импорта: " + e.Message + "\n" + e.InnerException);
            //}
        }
Example #2
0
        public static string getRemains(string FilePath)
        {
            List<spare_analogue> items = new List<spare_analogue>();
            string Message = "";

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

            XmlNodeList list = xd.GetElementsByTagName("Row");

            //int RemainsInputID = da.getRemainsInputID();
            MessageBox.Show("Будет импортировано " + list.Count + " записей.");
            string m1 = "";
            System.Globalization.CultureInfo ci =
              System.Globalization.CultureInfo.InstalledUICulture;
            System.Globalization.NumberFormatInfo ni = (System.Globalization.NumberFormatInfo)
              ci.NumberFormat.Clone();
            ni.NumberDecimalSeparator = ".";
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].HasChildNodes)
                {
                    decimal P = 0;
                    if (decimal.TryParse(list[i].ChildNodes[4].InnerText, out P))
                    {
                        P = decimal.Parse(list[i].ChildNodes[4].InnerText, ni);
                        da = new DataAccess();
                        spare_in_spare_income offering = new spare_in_spare_income();

                        //[id] - генериурется автоматически
                        //[num]
                        offering.num = 0;

                        //[description]
                        offering.description = "";

                        //[QIn]
                        decimal Q = 0;
                        Q = decimal.Parse(list[i].ChildNodes[3].InnerText, ni);
                        offering.QIn = Q;

                        //[PIn]
                        offering.PIn = P;

                        //[PInBasic]
                        offering.PInBasic = P;

                        //[VatRateID]
                        offering.vat_rate = da.getZeroVatRate();

                        //[Markup]
                        offering.Markup = 0;

                        //[SpareIncomeID] - в зависимости от поля #5
                        string WarehouseMarker = list[i].ChildNodes[5].InnerText;
                        int SpareIncomeID = 61;
                        if (WarehouseMarker.Contains("истина"))
                            SpareIncomeID = 61;
                        else
                            SpareIncomeID = 62;
                        offering.spare_income = da.SpareIncomeGet(SpareIncomeID);

                        //[CurrencyID]
                        offering.CurrencyID = 1;

                        //[S]
                        offering.S = Q * P;

                        //[SBasic]
                        offering.SBasic = Q * P;

                        //[POut]
                        offering.POut = P;

                        //[POutBasic]
                        offering.POutBasic = P;

                        //[QRest]
                        offering.QRest = Q;
                        string mess = "";

                        //===================================================== [SpareID]
                        string SpareCode1C = list[i].ChildNodes[0].InnerText;
                        mess += "1C:[" + SpareCode1C + "] - ";

                        //  search by code1C
                        spare sp = null;
                        sp = da.GetSpare(SpareCode1C);
                        string code = "X";
                        if (sp == null)
                        {
                            mess += "not found! ";

                            // search by spare code
                            code = list[i].ChildNodes[1].InnerText;
                            mess += "CODE:[" + code + "] - ";
                            sp = da.GetSpareByCode(code);
                        }
                        string name = "X";
                        if (sp == null)
                        {
                            mess += "not found! ";

                            // search by spare name
                            name = list[i].ChildNodes[2].InnerText;
                            mess += "NAME:[" + name + "] - ";
                            sp = da.GetSpare(name);
                        }
                        if (sp == null)
                            m1 += SpareCode1C + ", " + code + ", " + name + "\n";
                        else
                            da.InOfferingCreate(offering, sp.id);
                    }
                }
            }
            MessageBox.Show(m1);

            // Закрываем поток
            fs.Close();
            return Message;
        }
 public SpareIncomeSmart(int IncID)
 {
     InitializeComponent();
     DataAccess db = new DataAccess();
     Income = db.SpareIncomeGet(IncID);
     dgSpares.IsEnabled = false;
 }
 public void PrepareSpareIncome(int SpareIncomeId)
 {
     this.SpareIncomeID = SpareIncomeId;
     DataAccess da = new DataAccess();
     Income = da.SpareIncomeGet(SpareIncomeID);
 }