示例#1
0
        private void UpdateBtn_Click(object sender, EventArgs e)
        {
            Items aaItem = new Items();

            aaItem.Item_Type        = (int)TypeComboBox.SelectedValue;
            aaItem.Item_Category    = (int)CategoryComboBox.SelectedValue;
            aaItem.Vendor           = (int)VendorComboBox.SelectedValue;
            aaItem.Item_Tax_Level   = (int)TaxLevelComboBox.SelectedValue;
            aaItem.Item_Barcode     = BarcodeTxtBox.Text;
            aaItem.Item_Description = DescriptionTxtBox.Text;
            aaItem.Avalable_Qty     = double.Parse(QtyTxtBox.Text);
            aaItem.Render_Point     = double.Parse(RenderPointTxtBox.Text);
            // aaItem.Entry_Date = DateTxtBox.Text;
            aaItem.Sell_Price    = double.Parse(SellPriceTxtBox.Text);
            aaItem.Avg_Unit_Cost = double.Parse(AvgCostTxtBox.Text);
            // aaItem.PriceLevelID = int.Parse(SaleTxtBox.Text);
            // aaItem.Item_ID = int.Parse(IDTxtBox.Text);
            try
            {
                if (!ItemsMgmt.IsItemExist(BarcodeTxtBox.Text) || BarcodeTxtBox.Text == BarcodeToEditTxtBox.Text)
                {
                    ItemsMgmt.UpdateItemByID(aaItem);
                    MessageBox.Show("DONE");
                    this.Dispose();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Barcode " + BarcodeTxtBox.Text + " Already Exist in the system");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        private void UpdateItemBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validators.TxtBoxNotEmpty(BarcodeTxtBox.Text) || WithoutBarcodeChkBox.Checked)
                {
                    BarcodeTxtBox.BackColor = BarcodeTxtBoxBGColor;
                    double ParsingOutTester = 0;
                    if (Validators.TxtBoxNotEmpty(QtyTxtBox.Text) && double.TryParse(QtyTxtBox.Text, out ParsingOutTester))
                    {
                        QtyTxtBox.BackColor = QtyTxtBoxBGColor;
                        if (Validators.TxtBoxNotEmpty(RenderPointTxtBox.Text) && double.TryParse(RenderPointTxtBox.Text, out ParsingOutTester))
                        {
                            RenderPointTxtBox.BackColor = RenderTxtBoxBGColor;
                            if (Validators.TxtBoxNotEmpty(DescriptionTxtBox.Text))
                            {
                                DescriptionTxtBox.BackColor = DescriptionBGColor;
                                if (Validators.TxtBoxNotEmpty(SellPriceTxtBox.Text) && double.TryParse(SellPriceTxtBox.Text, out ParsingOutTester))
                                {
                                    SellPriceTxtBox.BackColor = SellPriceBGColor;
                                    if (Validators.TxtBoxNotEmpty(AvgCostTxtBox.Text) && double.TryParse(AvgCostTxtBox.Text, out ParsingOutTester))
                                    {
                                        AvgCostTxtBox.BackColor = AvgUnitCostBGColor;

                                        bool IsPriceLevelsEmpty = false;

                                        foreach (var tb in Pricing.Controls.OfType <TextBox>())
                                        {
                                            if (!Validators.TxtBoxNotEmpty(tb.Text) || !double.TryParse(tb.Text, out ParsingOutTester))
                                            {
                                                IsPriceLevelsEmpty = true;
                                                tb.BackColor       = SharedVariables.TxtBoxRequiredColor;
                                            }
                                            else
                                            {
                                                // tb.BackColor = Color.Black;
                                            }
                                        }
                                        if (IsPriceLevelsEmpty)
                                        {
                                            MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.PriceLevelsTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                            return;
                                        }
                                        else
                                        {
                                            bool IsBarcodeUsed = false;
                                            //CHECK IF NEW BARCODE IS  NOT CHECKED
                                            string OldBarcode;
                                            if (!WithoutBarcodeChkBox.Checked)
                                            {
                                                IsBarcodeUsed = ItemsMgmt.IsItemExist(BarcodeTxtBox.Text);
                                                if (ByBarcDescChkBox.Checked)
                                                {
                                                    OldBarcode = BarcodeToEditTxtBox.Text;
                                                }
                                                else
                                                {
                                                    OldBarcode = ItemDescriptionComboBox.SelectedValue.ToString();
                                                }
                                            }
                                            else
                                            {
                                                OldBarcode = WithoutBarcodeComboBox.SelectedValue.ToString();
                                            }
                                            Items aItem = new Items();
                                            aItem.Item_Type      = (int)TypeComboBox.SelectedValue;
                                            aItem.Item_Category  = (int)CategoryComboBox.SelectedValue;
                                            aItem.Vendor         = (int)VendorComboBox.SelectedValue;
                                            aItem.Item_Tax_Level = (int)TaxLevelComboBox.SelectedValue;
                                            if (WithoutBarcodeChkBox.Checked)
                                            {
                                                aItem.Item_Barcode = WithoutBarcodeComboBox.SelectedValue.ToString();
                                            }
                                            else
                                            {
                                                //aItem.IsWithoutBarcode = 0;
                                                aItem.Item_Barcode = BarcodeTxtBox.Text;
                                            }
                                            aItem.Item_ID = ItemsMgmt.SelectItemIDByBarcode(OldBarcode);
                                            if (!IsBarcodeUsed || WithoutBarcodeChkBox.Checked || OldBarcode == aItem.Item_Barcode)
                                            {
                                                aItem.Item_Description = DescriptionTxtBox.Text;
                                                aItem.Avalable_Qty     = double.Parse(QtyTxtBox.Text);
                                                aItem.Render_Point     = double.Parse(RenderPointTxtBox.Text);
                                                // aItem.Entry_Date = DateTime.Now.ToShortDateString();

                                                double aSellPrice = double.Parse(SellPriceTxtBox.Text);
                                                double aUnitCost  = double.Parse(AvgCostTxtBox.Text);
                                                double aTax       = double.Parse(ItemTaxLevelMgmt.SelectItemTaxByID(aItem.Item_Tax_Level));

                                                if (TaxEnclodedChkBox.Checked)
                                                {
                                                    aItem.Sell_Price    = Math.Round(aSellPrice / ((aTax / 100) + 1), 4);
                                                    aItem.Avg_Unit_Cost = Math.Round(aUnitCost / ((aTax / 100) + 1), 4);
                                                }
                                                else
                                                {
                                                    aItem.Sell_Price    = aSellPrice;
                                                    aItem.Avg_Unit_Cost = aUnitCost;
                                                }
                                                ItemsMgmt.UpdateItemByID(aItem);
                                                int ItemID = aItem.Item_ID;
                                                foreach (var tb in Pricing.Controls.OfType <TextBox>())
                                                {
                                                    Nullable <int> PriceLevelID = PriceLevelsMgmt.SelectPriceLevelIDByName(tb.Name);
                                                    if (PriceLevelID != null)
                                                    {
                                                        double atbSellPrice = double.Parse(tb.Text);

                                                        if (TaxEnclodedChkBox.Checked)
                                                        {
                                                            atbSellPrice = Math.Round(atbSellPrice / ((aTax / 100) + 1), 4);
                                                        }

                                                        Nullable <int> IsAddSpecialPriceOK;
                                                        if (SpecialPricesMgmt.IsSpecialPriceExist(ItemID, (int)PriceLevelID) == true)//exist update
                                                        {
                                                            IsAddSpecialPriceOK = SpecialPricesMgmt.UpdatePriceLevel(ItemID, (int)PriceLevelID, atbSellPrice);
                                                        }
                                                        else if (SpecialPricesMgmt.IsSpecialPriceExist(ItemID, (int)PriceLevelID) == false)//not exist create new
                                                        {
                                                            IsAddSpecialPriceOK = SpecialPricesMgmt.AddSpecialPrice(ItemID, (int)PriceLevelID, atbSellPrice);
                                                        } //null database error
                                                        else
                                                        {
                                                            MessageBox.Show(MsgTxt.UnexpectedError + "DataBase: SpecialPricesMgmt.AddSpecialPrice", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                            return;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("UNEXPECTED ERROR !!ITEM ADDED SUCCESSFULY, NOT PRICE LEVELS ADDED " + "\n" + "PLEASE ADD PRICE LEVELS MANUALLY FROM EDIT ITEM PAGE", "PRICE LEVEL ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                        throw new System.ArgumentException("Parameter cannot be null", "original");
                                                    }
                                                }
                                                MessageBox.Show(MsgTxt.UpdateSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            }
                                            else
                                            {
                                                MessageBox.Show(MsgTxt.BarcodeTxt + " " + MsgTxt.AlreadyUsedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                                BarcodeTxtBox.Text = "";
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.UnitCostTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        AvgCostTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                                        AvgCostTxtBox.Focus();
                                    }
                                }
                                else
                                {
                                    MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.SellingPriceTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    SellPriceTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                                    SellPriceTxtBox.Focus();
                                }
                            }
                            else
                            {
                                MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.DescriptionTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                DescriptionTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                                DescriptionTxtBox.Focus();
                            }
                        }
                        else
                        {
                            MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.RenderPointTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            RenderPointTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                            RenderPointTxtBox.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.ValidQtyTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        QtyTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                        QtyTxtBox.Focus();
                    }
                }
                else
                {
                    MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.BarcodeTxt + "\n2)" + MsgTxt.IfNotBarChkWithoutBarcodeTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    BarcodeTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                    BarcodeTxtBox.Focus();
                }
            }
            catch (Exception ex)
            {
                IsUpdating = false;
                MessageBox.Show(MsgTxt.UnexpectedError + "\nException: IN[UpdateItemBtn_Click] \n" + ex.ToString(), MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                throw;
            }
        }