Esempio n. 1
0
        //[BARCODE FUNCTIONS]
        /// <summary>
        /// ADD ITEM USING BARCODE
        /// this is one of the major function which is used to add item using its barcode to the
        /// TELDGVIEW with the following columns
        /// [Barcode] [Qty] [Description] [PricePerUnit] [Tax]  [PriceTotal] [AvalQty]
        /// And this function loocks a bool called IsAddingItem
        /// Function Version 1.00
        /// Last Edited By Sari Sultan On October,7,2013
        /// changed sell price to AvgUnitCost TeldgView.Rows[RowNum].Cells["PricePerUnit"].Value = aItemTable.Rows[0]["AvgUnitCost"].ToString();
        /// </summary>
        /// <param name="aBarcode"></param>
        /// <param name="IsFromGun"></param>
        private void AddItemUsingBarcode(string aBarcode, bool IsFromGun = false)
        {
            try
            {
                double    TotwgtPrice = 0;
                bool      dowgt       = false;
                DataTable aItemTable  = null;

                if (aThereIsWeigth && IsFromGun)
                {
                    if (aBarcode.Length > BarcodeLength)
                    {
                        aBarcode = aBarcode.Substring(0, BarcodeLength);
                        if (ItemsMgmt.IsItemWgtExist(aBarcode))
                        {
                            aItemTable = ItemsMgmt.SelectItemByBarCode(aBarcode);
                            string tempcoststr = aBarcode.Substring(BarcodeLength, aBarcode.Length - BarcodeLength);
                            if (double.TryParse(tempcoststr, out TotwgtPrice))
                            {
                                dowgt = true;
                            }
                        }
                        else
                        {
                            aItemTable = ItemsMgmt.SelectItemByBarCode(aBarcode);
                        }
                    }
                    else
                    {
                        aItemTable = ItemsMgmt.SelectItemByBarCode(aBarcode);
                    }
                }
                else
                {
                    aItemTable = ItemsMgmt.SelectItemByBarCode(aBarcode);
                }

                if (aItemTable != null)
                {
                    if (aItemTable.Rows.Count == 1)
                    {
                        double TaxPer = double.Parse(ItemTaxLevelMgmt.SelectItemTaxByID(int.Parse(aItemTable.Rows[0]["TaxLevel"].ToString())));
                        foreach (DataGridViewRow r in TeldgView.Rows)
                        {
                            if (TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString() == aItemTable.Rows[0]["Barcode"].ToString())
                            {
                                TeldgView.ClearSelection();
                                if (dowgt)
                                {
                                    TeldgView.Rows[r.Index].Cells["Qty"].Value = Convert.ToDouble(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString()) + Math.Round(TotwgtPrice / DivisionScale / (double.Parse(aItemTable.Rows[0]["SellPrice"].ToString()) * (1 + TaxPer / 100)), 3);
                                }
                                else
                                {
                                    TeldgView.Rows[r.Index].Cells["Qty"].Value = Convert.ToDouble(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString()) + 1;
                                }
                                TeldgView.Rows[r.Index].Cells["PriceTotal"].Value = Math.Round(Convert.ToDouble(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString()) * Convert.ToDouble(TeldgView.Rows[r.Index].Cells["PricePerUnit"].Value.ToString()), 3);
                                TeldgView.Rows[r.Index].Selected = true;
                                return;
                            }
                        }
                        IsAddingItem = true;
                        TeldgView.ClearSelection();
                        int RowNum = TeldgView.Rows.Add();
                        TeldgView.Rows[RowNum].Cells["Barcode"].Value      = aItemTable.Rows[0]["Barcode"].ToString();
                        TeldgView.Rows[RowNum].Cells["Description"].Value  = aItemTable.Rows[0]["Description"].ToString();
                        TeldgView.Rows[RowNum].Cells["PricePerUnit"].Value = aItemTable.Rows[0]["AvgUnitCost"].ToString();
                        if (dowgt)
                        {
                            TeldgView.Rows[RowNum].Cells["Qty"].Value = Math.Round((TotwgtPrice / DivisionScale) / (double.Parse(aItemTable.Rows[0]["SellPrice"].ToString()) * (1 + TaxPer / 100)), 3);
                        }
                        else
                        {
                            TeldgView.Rows[RowNum].Cells["Qty"].Value = 1;
                        }
                        TeldgView.Rows[RowNum].Cells["PriceTotal"].Value = Math.Round(double.Parse(TeldgView.Rows[RowNum].Cells["PricePerUnit"].Value.ToString()) * Convert.ToDouble(TeldgView.Rows[RowNum].Cells["Qty"].Value.ToString()), 3);
                        TeldgView.Rows[RowNum].Cells["Tax"].Value        = TaxPer;
                        TeldgView.Rows[RowNum].Cells["AvalQty"].Value    = aItemTable.Rows[0]["Qty"].ToString();
                        TeldgView.Rows[RowNum].Selected = true;
                    }
                    else
                    {
                        MessageBox.Show(MsgTxt.ItemNotFoundTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    IsAddingItem = false;
                }
            }
            catch (Exception ex)
            {
                IsAddingItem = false;
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [AddItemUsingBarcode] \n Exception: \n" + ex.ToString(), MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }