private void btnNext_Click(object sender, RoutedEventArgs e)
 {
     Stage++;
     if (Stage == 1)
     {
         dgSpares.IsEnabled = true;
         btnNext.Content = "Сохранить";
     }
     else
         if (Stage == 2)
         {
             foreach (SpareInSpareIncomeView sisi in offerings)
             {
                 //sisi.SpareName
                 //sisi.BrandName
                 //sisi.SpareCode
                 //sisi.SpareCodeShatem
                 DataAccess db = new DataAccess();
                 int SpareID = sisi.SpareID.Value;
                 db.InOfferingCreate(sisi.SpareID.Value, sisi.QIn, sisi.PIn.Value, sisi.Markup, sisi.POut.Value, sisi.S.Value, sisi.SpareIncomeID.Value);
                 SpareContainer.Instance.Update(SpareID);
             }
             Close();
         }
 }
        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;
        }