示例#1
0
        public void LoadItem(int id)
        {
            DataAccess da = new DataAccess();
            _spare = da.GetSpare(id);
            if (_spare != null)
            {
                IsNew = false;
                if (_spare.brand == null)
                    _spare.brandReference.Load();
                if (_spare.spare_group == null)
                    _spare.spare_groupReference.Load();
                if (_spare.unit == null)
                    _spare.unitReference.Load();
                _id = _spare.id;
                string Name = _spare.name;
                string Code = _spare.code;
                string CodeShatem = _spare.codeShatem;
                string QDemand = _spare.q_demand.ToString();
                int GroupID = _spare.spare_group.id;
                int BrandID = _spare.brand.id;
                int UnitID = _spare.unit.id;
                string BrandName = _spare.brand.name;
                string GroupName = _spare.spare_group.name;
                string UnitName = _spare.unit.name;
                string Description = _spare.description;
                OldBrandName = BrandName;
                OldGroupID = GroupID;

                edtName.Text = Name;
                edtCode.Text = Code;
                edtCodeShatem.Text = CodeShatem;
                edtQ_Demand.Text = QDemand;
                edtGroup.SelectedValue = GroupID;
                edtBrand.SelectedValue = BrandID;
                edtUnit.SelectedValue = UnitID;
                edtDescr.Text = Description;
            }
        }
示例#2
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;
        }
示例#3
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;
        }
示例#4
0
        // ЗАПЧАСТЬ - УДАЛИТЬ
        public void SpareDelete(SpareView item)
        {
            if (!ready())
                return;
            //try
            {
                DataAccess da = new DataAccess();
                int cnt = SpareContainer.Instance.Spares.Where(s => s.BrandID == item.BrandID && s.GroupID == item.GroupID).Count();
                spare sp = da.GetSpare(item.id);
                if (sp.spare_group == null)
                    sp.spare_groupReference.Load();
                if (sp.brand == null)
                    sp.brandReference.Load();
                int BrandID = item.BrandID;
                int GroupID = item.GroupID;
                da.SpareDelete(item.id);
                SpareContainer.Instance.Remove(item.id);

                // проверить, не последняя ли это деталь в брэнде в данной группе
                if (cnt < 2)
                {
                    da.SpareGroupDelete(BrandID, GroupID);
                }
            }

            //catch (Exception ex)
            {
                //    this.Log(ex.Message);
            }
        }
示例#5
0
        private void BackgroundShowDetails_DoWork(object sender, DoWorkEventArgs e)
        {
            // DETAILED INFO
            IList selectedItems = e.Argument as IList;
            if (selectedItems.Count == 0)
            {
                DetailSpareInfo_Brand = "";
                DetailSpareInfo_Group = "";
                DetailSpareInfo_Name = "";
                Detail_Incomes = null;
                Detail_Analogues = null;
            }
            else
            {
                SpareView selected = selectedItems[0] as SpareView;
                DetailSpareInfo_Brand = selected.BrandName;
                DetailSpareInfo_Name = selected.name;

                // построим путь по группам к запчасти
                // текущая группа
                DataAccess db = new DataAccess();
                spare s = db.GetSpare(selected.id);
                string gp = s.spare_group.name;

                // родительская
                if (s.spare_group1 != null)
                    gp = s.spare_group1.name + "/" + gp;

                // дедушка
                if (s.spare_group2 != null)
                    gp = s.spare_group2.name + "/" + gp;

                // прадедушка
                if (s.spare_group3 != null)
                    gp = s.spare_group3.name + "/" + gp;
                DetailSpareInfo_Group = gp;

                // INCOMES & ANALOGS WINDOWS
                // anlogues
                Detail_Analogues = db.GetAnalogues(selected.id);

                // incomes
                Detail_Incomes = db.GetIncomes(selected.id);
                foreach (SpareInSpareIncomeView i in Detail_Incomes)
                {
                    decimal POutBasic = 0;
                    decimal PInBasic = 0;
                    if (!i.POutBasic.HasValue)
                    {
                        string IncomeCurrencyCode = i.CurrencyCode;

                        decimal PIn = i.PIn.Value;
                        POutBasic = CurrencyHelper.GetBasicPrice(IncomeCurrencyCode, PIn);
                    }
                    else
                    {
                        POutBasic = i.POutBasic.Value;
                    }
                    if (i.PInBasic.HasValue)
                    {
                        PInBasic = i.PInBasic.Value;
                    }
                    else
                    {
                        string IncomeCurrencyCode = i.CurrencyCode;
                        decimal PIn = i.PIn.Value;
                        PInBasic = CurrencyHelper.GetBasicPrice(IncomeCurrencyCode, PIn);
                    }
                    i.DF_PriceInCurrency = CurrencyHelper.GetPrice(currentCurrencyName, POutBasic);
                    i.DF_PriceInCurrencyIn = CurrencyHelper.GetPrice(currentCurrencyName, PInBasic);

                    string strDate = "";
                    if (i.SpareIncomeDate.Value.Day < 10)
                        strDate += "0";
                    strDate += i.SpareIncomeDate.Value.Day + ".";
                    if (i.SpareIncomeDate.Value.Month < 10)
                        strDate += "0";
                    strDate += i.SpareIncomeDate.Value.Month + ".";
                    strDate += i.SpareIncomeDate.Value.Year;
                    i.DF_Date = strDate;
                }
            }
        }
示例#6
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;
        }
示例#7
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;
                }
            }
        }