Esempio n. 1
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;
        }
        private void AddNewOffering()
        {
            string _SpareName = GetSelectedSpareName();
            int _SpareID = GetSelectedSpareId();

            // проверить, есть ли списке введенных данный товар
            bool InRevisionExist = da.GetRemains(_SpareIncomeID).Where(x => x.SpareID == _SpareID).Count() > 0;

            // если есть, спросить, добавить ли его новой позицией или приплюсовать 1 шт. к уже внесенному
            if (InRevisionExist)
            {
                string QM = "Добавить отдельной позицией?";

                // (ДА - появится новая строчка с данным товаром; НЕТ - добавится 1 шт. к уже существущей строчке с товаром)?";
                if (MessageBox.Show(QM, "Есть такая деталь в списке!", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    // добавить новой позицией
                    spare_in_spare_income offering = new spare_in_spare_income();
                    offering.id = -1;
                    offering.Markup = 1;
                    offering.num = ++_OfferingNumber;
                    offering.PIn = 1;
                    offering.QIn = 1;
                    offering.POut = 1;
                    offering.S = 1;

                    offering.PInBasic = 0;
                    offering.POutBasic = 0;
                    offering.SBasic = 0;

                    if (CurrencyRateCode == "BYR")
                        offering.CurrencyID = 1;
                    else
                        if (CurrencyRateCode == "USD")
                            offering.CurrencyID = 2;
                        else
                            if (CurrencyRateCode == "EUR")
                                offering.CurrencyID = 3;
                            else
                                if (CurrencyRateCode == "RUR")
                                    offering.CurrencyID = 4;

                    string VATName = "Без НДС";
                    da.InOfferingCreate(offering, _SpareID, _SpareIncomeID, VATName);
                    SpareContainer.Instance.Update(_SpareID);
                }
                else
                {
                    // приплюсовать штуку к уже внесенному
                    //#TODO
                    // пока не реализовано
                }
            }
            else
            {
                spare_in_spare_income offering = new spare_in_spare_income();
                offering.id = -1;
                offering.Markup = 1;
                offering.num = ++_OfferingNumber;
                offering.PIn = 1;
                offering.QIn = 1;
                offering.POut = 1;
                offering.S = 1;

                offering.PInBasic = 0;
                offering.POutBasic = 0;
                offering.SBasic = 0;

                string VATName = "Без НДС";

                if (CurrencyRateCode == "BYR")
                    offering.CurrencyID = 1;
                else
                    if (CurrencyRateCode == "USD")
                        offering.CurrencyID = 2;
                    else
                        if (CurrencyRateCode == "EUR")
                            offering.CurrencyID = 3;
                        else
                            if (CurrencyRateCode == "RUR")
                                offering.CurrencyID = 4;

                da.InOfferingCreate(offering, _SpareID, _SpareIncomeID, VATName);
                SpareContainer.Instance.Update(_SpareID);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the spare_in_spare_income EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTospare_in_spare_income(spare_in_spare_income spare_in_spare_income)
 {
     base.AddObject("spare_in_spare_income", spare_in_spare_income);
 }
 private spare_in_spare_income getItemFromFields()
 {
     spare_in_spare_income item = new spare_in_spare_income();
     try
     {
         // set currency
         item.CurrencyID = da.GetCurrency(this.CurrentCurrencyCode).id;
         item.id = this._OfferingID;
         item.Markup = 0;//Double.Parse(edtMakeup.Text);
         item.num = _OfferingNumber + 1;
         decimal p = decimal.Parse(edtPriceFull.Text);
         item.POut = p;
         item.PIn = p;
         item.QIn = decimal.Parse(edtQ.Text);
         item.S = sum;
         item.QRest = item.QIn;
     }
     catch (Exception)
     {
         MessageBox.Show("Проверьте правильность введенных данных");
         item = null;
     }
     return item;
 }
Esempio n. 5
0
        public void InOfferingEdit(spare_in_spare_income e, string VatRateName)
        {
            spare_in_spare_income o = objDataContext.spare_in_spare_income.FirstOrDefault(i => i.id == e.id);
            if (o != null)
            {
                string CurrentCurrencyCode = GetCurrency(o.CurrencyID.Value).code;

                o.description = e.description;
                o.QIn = e.QIn;
                o.QRest = e.QRest;
                o.Markup = e.Markup;
                o.vat_rate = objDataContext.vat_rate.FirstOrDefault(s => s.name == VatRateName);

                o.PIn = e.PIn;
                o.PInBasic = CurrencyHelper.GetBasicPrice(CurrentCurrencyCode, o.PIn.Value);
                o.POut = e.POut;
                o.POutBasic = o.PInBasic * (1 + o.Markup / 100 + o.vat_rate.rate / 100);
                o.S = e.S;
                o.SBasic = o.PIn * o.QIn;

                spare sp = objDataContext.spares.FirstOrDefault(s => s.id == o.spare.id);
                sp.q_rest += e.QIn - o.QIn;

                objDataContext.SaveChanges();
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Create a new spare_in_spare_income object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="qIn">Initial value of the QIn property.</param>
 /// <param name="markup">Initial value of the Markup property.</param>
 public static spare_in_spare_income Createspare_in_spare_income(global::System.Int32 id, global::System.Decimal qIn, global::System.Decimal markup)
 {
     spare_in_spare_income spare_in_spare_income = new spare_in_spare_income();
     spare_in_spare_income.id = id;
     spare_in_spare_income.QIn = qIn;
     spare_in_spare_income.Markup = markup;
     return spare_in_spare_income;
 }
Esempio n. 7
0
        public int InOfferingCreate(spare_in_spare_income _obj, string SpareCode1C, int spareIncomeId, string VatRateName)
        {
            try
            {
                _obj.QRest = _obj.QIn;
                spare sp = objDataContext.spares.FirstOrDefault(s => s.code1C == SpareCode1C);
                _obj.spare = sp;
                _obj.spare_income = objDataContext.spare_income.FirstOrDefault(s => s.id == spareIncomeId);
                _obj.vat_rate = objDataContext.vat_rate.FirstOrDefault(s => s.name == VatRateName);
                objDataContext.AddTospare_in_spare_income(_obj);

                //save quantity
                sp.q_rest += _obj.QIn;
                objDataContext.SaveChanges();
                return 0;
            }
            catch (Exception)
            {
                return 1;
            }
        }
Esempio n. 8
0
        public void InOfferingCreate(int spareId, decimal q, decimal pin, decimal m, decimal pout, decimal s, double incomeId)
        {
            spare_in_spare_income _obj = new spare_in_spare_income();
            _obj.description = "";
            _obj.Markup = m;
            _obj.num = 0;
            _obj.PIn = pin;
            _obj.POut = pout;
            _obj.QIn = q;
            _obj.QRest = q;
            _obj.S = s;

            spare sp = objDataContext.spares.FirstOrDefault(spp => spp.id == spareId);
            spare_income income = objDataContext.spare_income.FirstOrDefault(sii => sii.id == incomeId);
            _obj.spare = sp;
            _obj.spare_income = income;
            _obj.vat_rate = objDataContext.vat_rate.FirstOrDefault(r => r.name == "Без НДС");
            if (income.currency == null)
                income.currencyReference.Load();
            _obj.CurrencyID = income.currency.id;
            string CurrentCurrencyCode = GetCurrency(_obj.CurrencyID.Value).code;
            _obj.QRest = _obj.QIn;
            _obj.PInBasic = CurrencyHelper.GetBasicPrice(CurrentCurrencyCode, _obj.PIn.Value);
            _obj.POutBasic = _obj.PInBasic * (1 + _obj.Markup / 100 + _obj.vat_rate.rate / 100);
            _obj.SBasic = _obj.PIn * _obj.QIn;

            objDataContext.AddTospare_in_spare_income(_obj);

            //save quantity
            sp.q_rest += _obj.QIn;
            objDataContext.SaveChanges();
        }
Esempio n. 9
0
        public void InOfferingCreate(spare_in_spare_income _obj)
        {
            string CurrentCurrencyCode = GetCurrency(_obj.CurrencyID.Value).code;

            _obj.QRest = _obj.QIn;
            _obj.PInBasic = CurrencyHelper.GetBasicPrice(CurrentCurrencyCode, _obj.PIn.Value);
            _obj.POutBasic = _obj.PInBasic * (1 + _obj.Markup / 100 + _obj.vat_rate.rate / 100);
            _obj.SBasic = _obj.PIn * _obj.QIn;

            objDataContext.AddTospare_in_spare_income(_obj);

            //objDataContext.Attach(_obj);
            //save quantity
            _obj.spare.q_rest += _obj.QIn;
            objDataContext.SaveChanges();
        }
Esempio n. 10
0
        public void InOfferingCreate(spare_in_spare_income _obj, int spareId, int spareIncomeId, string VatRateName)
        {
            string CurrentCurrencyCode = GetCurrency(_obj.CurrencyID.Value).code;

            _obj.QRest = _obj.QIn;
            spare sp = objDataContext.spares.FirstOrDefault(s => s.id == spareId);
            _obj.spare = sp;
            _obj.spare_income = objDataContext.spare_income.FirstOrDefault(s => s.id == spareIncomeId);
            _obj.vat_rate = objDataContext.vat_rate.FirstOrDefault(s => s.name == VatRateName);

            if (CurrentCurrencyCode == CurrencyHelper.BasicCurrencyCode)
            {
                _obj.POutBasic = _obj.POut;
                _obj.PInBasic = _obj.PIn;
            }
            else
            {
                _obj.POutBasic = CurrencyHelper.GetBasicPrice(CurrentCurrencyCode, _obj.POut.Value);
                _obj.PInBasic = CurrencyHelper.GetBasicPrice(CurrentCurrencyCode, _obj.PIn.Value);
            }
            _obj.SBasic = _obj.POutBasic * _obj.QIn;

            objDataContext.AddTospare_in_spare_income(_obj);

            //save quantity
            sp.q_rest += _obj.QIn;
            objDataContext.SaveChanges();
        }
Esempio n. 11
0
 public void InOfferingCreate(spare_in_spare_income _obj, int SpareID)
 {
     objDataContext.AddTospare_in_spare_income(_obj);
     spare sp = objDataContext.spares.FirstOrDefault(s => s.id == SpareID);
     _obj.spare = sp;
     sp.q_rest += _obj.QIn;
     objDataContext.SaveChanges();
 }