Exemple #1
0
        private void btn_add_prodname_Click(object sender, EventArgs e)
        {
            AddProduct_Form prod_add_frm = new AddProduct_Form();

            prod_add_frm.Show();
            prod_add_frm.FormClosed += delegate(object senderProdAddFrm, FormClosedEventArgs eProdAddFrm)
            {
                all_prod_names = ProductInfo_Main_Form.conn.GetProductSuggestions("");
                //all_valid_rems = ProductInfo_Main_Form.conn.GetValidRemainders(ProductInfo_Main_Form.ActiveStoreID, true);

                LoadProdNamesList();
            };
        }
        private void add_remainders_list_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            pressed_name_keystrokes = "";
            if (submit_clicked && !add_remainders_list.Rows[e.RowIndex].IsNewRow)
            {
                HighlightNonCompleteFields(add_remainders_list.Rows[e.RowIndex]);
            }
            if (add_remainders_list.Columns[add_rem_barcode_col.Index].Index == e.ColumnIndex && null != add_remainders_list.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
            {
                Product ProdJustScanned = ProductInfo_Main_Form.conn.GetProductByBarCode(add_remainders_list.Rows[e.RowIndex].Cells[add_rem_barcode_col.Index].EditedFormattedValue.ToString());
                if ("nameless" == ProdJustScanned.name)
                {
                    if (DialogResult.Yes == MessageBox.Show("შტრიხ–კოდი არ არის დარეგისტრირებული. გსურთ პროდუქტის ბაზაში დამატება?", "შეცდომა!", MessageBoxButtons.YesNo))
                    {
                        AddProduct_Form add_scanned_frm = new AddProduct_Form();
                        add_scanned_frm.Show();
                        add_scanned_frm.Controls["barcode_txt"].Text = add_remainders_list.Rows[e.RowIndex].Cells[add_rem_barcode_col.Index].Value.ToString();
                        add_scanned_frm.Controls["name_txt"].Focus();
                        add_scanned_frm.Controls["prod_add_btn"].Click += new EventHandler(AddRemainders_Form_Click);
                    }
                    else
                    {
                        add_remainders_list.Rows[e.RowIndex].Cells[add_rem_barcode_col.Index].Value = "000000000";
                    }
                }
                else
                {
                    try
                    {
                        add_remainders_list.Rows[e.RowIndex].Cells[add_rem_name_col.Index].Value = ProdJustScanned.name;
                    }
                    catch (System.ArgumentException)
                    {
                    }
                    finally
                    {
                    }
                }
            }

            if (add_remainders_list.Columns[add_rem_name_col.Index].Index == e.ColumnIndex && null != add_remainders_list.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
            {
                foreach (Product nXprod in all_products)
                {
                    if (add_remainders_list.Rows[e.RowIndex].Cells[add_rem_name_col.Index].Value.ToString() == nXprod.name)
                    {
                        add_remainders_list.Rows[e.RowIndex].Cells[add_rem_barcode_col.Index].Value = nXprod.barcode;
                        break;
                    }
                }
            }

            try
            {
                if (null != add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_count_col.Index].Value)
                {
                    if (null != add_remainders_list.Rows[e.RowIndex].Cells[add_rem_count_type_col.Index].Value)
                    {
                        if ("ცალობით" == add_remainders_list.Rows[e.RowIndex].Cells[add_rem_count_type_col.Index].Value.ToString())
                        {
                            decimal row_piece_price = 0.0m;
                            decimal row_sum_price   = 0.0m;

                            decimal row_piece_count = 0.0m;
                            if (null != add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_count_col.Index].Value)
                            {
                                row_piece_count = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_count_col.Index].Value.ToString());
                            }

                            if (null != add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_price_col.Index].Value)
                            {
                                row_piece_price = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_price_col.Index].Value.ToString());
                                row_sum_price   = row_piece_count * row_piece_price;
                                add_remainders_list.Rows[e.RowIndex].Cells[add_rem_sum_price_col.Index].Value = row_sum_price; // * ((decimal)add_remainders_list.Rows[e.RowIndex].Cells[add_rem_storeid_col.Index].Value + (decimal)add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_price_col.Index].Value);
                                Row_Pricing[e.RowIndex] = row_sum_price;
                                //
                                decimal row_sell_price = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[add_rem_sell_price_col.Index].Value.ToString());
                                add_remainders_list.Rows[e.RowIndex].Cells[add_rem_namati_col.Index].Value
                                    = ((row_sell_price >= row_piece_price) ? "+" : "") + Math.Round(((row_sell_price - row_piece_price) / row_piece_price) * 100, 2) + "%";
                                add_remainders_list.Rows[e.RowIndex].Cells[add_rem_namati_col.Index].Style.BackColor
                                    = (row_sell_price >= row_piece_price) ? Color.LightGray : Color.Red;
                                //add_remainders_list.Rows[e.RowIndex].Cells[add_rem_namati_col.Index].Style.ForeColor
                                //    = (row_sell_price >= row_piece_price) ? Color.Black : Color.White;
                                //
                                UpdateSumPrice();
                            }
                        }
                        else
                        {
                            decimal pack_count      = 0.0m;
                            decimal row_piece_price = 0.0m;
                            decimal row_sum_price   = 0.0m;

                            decimal row_piece_count = 0.0m;
                            if (null != add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_count_col.Index].Value)
                            {
                                row_piece_count = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_count_col.Index].Value.ToString());
                            }

                            if (null != add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_price_col.Index].Value && null != add_remainders_list.Rows[e.RowIndex].Cells[add_rem_capacity_col.Index].Value)
                            {
                                row_piece_price = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_price_col.Index].Value.ToString());
                                pack_count      = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[add_rem_capacity_col.Index].Value.ToString());
                                row_sum_price   = row_piece_count * pack_count * row_piece_price;
                                add_remainders_list.Rows[e.RowIndex].Cells[add_rem_sum_price_col.Index].Value = row_sum_price; // * ((decimal)add_remainders_list.Rows[e.RowIndex].Cells[add_rem_storeid_col.Index].Value + (decimal)add_remainders_list.Rows[e.RowIndex].Cells[add_rem_piece_price_col.Index].Value);
                                Row_Pricing[e.RowIndex] = row_sum_price;
                                //
                                decimal row_sell_price = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[add_rem_sell_price_col.Index].Value.ToString());
                                add_remainders_list.Rows[e.RowIndex].Cells[add_rem_namati_col.Index].Value
                                    = ((row_sell_price >= row_piece_price) ? "+" : "") + Math.Round(((row_sell_price - row_piece_price) / row_piece_price) * 100, 2) + "%";
                                add_remainders_list.Rows[e.RowIndex].Cells[add_rem_namati_col.Index].Style.BackColor
                                    = (row_sell_price >= row_piece_price) ? Color.LightGray : Color.Red;
                                //add_remainders_list.Rows[e.RowIndex].Cells[add_rem_namati_col.Index].Style.ForeColor
                                //    = (row_sell_price >= row_piece_price) ? Color.Black : Color.White;
                                //
                                UpdateSumPrice();
                            }
                        }
                    }
                }
            }
            catch (FormatException)
            {
                status_bar_lbl.Text = "შეავსეთ ველები შესაბამისი ფორმატით. ";
            }
            catch (NullReferenceException)//not needed
            {
                status_bar_lbl.Text = "ყველა ველი არაა შევსებული. ";
            }
        }
Exemple #3
0
        private void add_remainders_list_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            pressed_name_keystrokes = "";
            if (submit_clicked && !add_remainders_list.Rows[e.RowIndex].IsNewRow)
            {
                HighlightNonCompleteFields(add_remainders_list.Rows[e.RowIndex]);
            }
            if (add_remainders_list.Columns["sell_rem_barcode_col"].Index == e.ColumnIndex && null != add_remainders_list.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
            {
                Product ProdJustScanned = ProductInfo_Main_Form.conn.GetProductByBarCode(add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_barcode_col"].EditedFormattedValue.ToString());
                if ("nameless" == ProdJustScanned.name)
                {
                    if (DialogResult.Yes == MessageBox.Show("შტრიხ–კოდი არ არის დარეგისტრირებული. გსურთ პროდუქტის ბაზაში დამატება?", "შეცდომა!", MessageBoxButtons.YesNo))
                    {
                        AddProduct_Form add_scanned_frm = new AddProduct_Form();
                        add_scanned_frm.Show();
                        add_scanned_frm.Controls["barcode_txt"].Text = add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_barcode_col"].Value.ToString();
                        add_scanned_frm.Controls["name_txt"].Focus();
                        add_scanned_frm.Controls["prod_add_btn"].Click += new EventHandler(Sell_Form_Click);
                    }
                    else
                    {
                        add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_barcode_col"].Value = "000000000";
                    }
                }
                else
                {
                    add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_name_col"].Value = ProdJustScanned.name;
                }

                IEnumerable <Remainder> query = new List <Remainder>();
                query = from r in all_rems
                        where r.product_barcode == add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_barcode_col.Index].Value.ToString()
                        select r;
                Remainder[] query_toarray = query.ToArray();

                add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_remaining_col"].Value = query.Sum(r => r.remaining_pieces).ToString("G4") + " (სულ)";

                if (query_toarray.Length > 0)
                {
                    add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_capacity_col.Index].Value      = query_toarray[0].pack_capacity.ToString("G4");
                    add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_initial_price_col.Index].Value = query_toarray[0].buy_price.ToString("G4") + " (#" + query_toarray[0].storehouse_id.ToString() + ")";
                }
                else
                {
                    MessageBox.Show("ეს პროდუქტი საწყობების ბაზაში არაა დარჩენილი. ");
                    add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_barcode_col.Index].Value = "000000000";
                }
            }

            if (add_remainders_list.Columns[sell_rem_name_col.Index].Index == e.ColumnIndex && null != add_remainders_list.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
            {
                foreach (Product nXprod in all_products)
                {
                    if (add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_name_col.Index].Value.ToString() == nXprod.name)
                    {
                        add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_barcode_col.Index].Value = nXprod.barcode;

                        IEnumerable <Remainder> query = new List <Remainder>();
                        query = from r in all_rems
                                where r.product_barcode == add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_barcode_col.Index].Value.ToString()
                                select r;
                        Remainder[] query_toarray = query.ToArray();

                        add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_remaining_col"].Value = query.Sum(r => r.remaining_pieces).ToString("G4") + " (სულ)";

                        if (query_toarray.Length > 0)
                        {
                            add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_capacity_col.Index].Value      = query_toarray[0].pack_capacity.ToString("G4");
                            add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_initial_price_col.Index].Value = query_toarray[0].buy_price.ToString("G4") + " (#" + query_toarray[0].storehouse_id.ToString() + ")";
                        }
                        else
                        {
                            MessageBox.Show("ეს პროდუქტი საწყობების ბაზაში არაა დარჩენილი. ");
                            add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_barcode_col"].Value = "000000000";
                        }

                        break;
                    }
                }
            }

            if (add_remainders_list.Columns[sell_rem_storeid_col.Index].Index == e.ColumnIndex && null != add_remainders_list.Rows[e.RowIndex].Cells[e.ColumnIndex].Value && null != add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_barcode_col.Index].Value)
            {
                int CurrentStoreID            = Int32.Parse(add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_storeid_col.Index].Value.ToString());
                IEnumerable <Remainder> query = new List <Remainder>();
                query = from r in all_rems
                        where r.product_barcode == add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_barcode_col.Index].Value.ToString() &&
                        CurrentStoreID == r.storehouse_id
                        select r;

                var StoreRems = from rem in query
                                group rem by rem.storehouse_id into storrem
                                select new { StoreID = storrem.Key, remaining_items = storrem.Sum(rem => rem.remaining_pieces) };
                var rem_rem = (from sr in StoreRems
                               where CurrentStoreID == sr.StoreID
                               select sr.remaining_items).ToArray();
                if (rem_rem.Length > 0)
                {
                    add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_remaining_col"].Value = rem_rem[0].ToString("G4") + " (#" + CurrentStoreID.ToString() + ")";
                }
                else
                {
                    add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_remaining_col"].Value = 0.ToString("G4") + " (#" + CurrentStoreID.ToString() + ")";
                }

                Remainder[] query_toarray = query.ToArray();
                if (query_toarray.Length > 0)
                {
                    add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_initial_price_col.Index].Value = query_toarray[0].buy_price.ToString("G4") + " (#" + query_toarray[0].storehouse_id.ToString() + ")";
                }
            }

            if (add_remainders_list.Columns[sell_rem_piece_count_col.Index].Index == e.ColumnIndex &&
                null != add_remainders_list.Rows[e.RowIndex].Cells[e.ColumnIndex].Value && null != add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_barcode_col.Index].Value &&
                null != add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_storeid_col.Index].Value)
            {
                int CurrentStoreID            = Int32.Parse(add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_storeid_col.Index].Value.ToString());
                IEnumerable <Remainder> query = new List <Remainder>();
                query = from r in all_rems
                        where r.product_barcode == add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_barcode_col.Index].Value.ToString() &&
                        CurrentStoreID == r.storehouse_id
                        select r;

                var StoreRems = from rem in query
                                group rem by rem.storehouse_id into storrem
                                select new { StoreID = storrem.Key, remaining_items = storrem.Sum(rem => rem.remaining_pieces) };
                var rem_rem = (from sr in StoreRems
                               where CurrentStoreID == sr.StoreID
                               select sr.remaining_items).ToArray();
                if (rem_rem.Length > 0)
                {
                    add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_remaining_col"].Value = rem_rem[0].ToString("G4") + " (#" + CurrentStoreID.ToString() + ")";
                }
                else
                {
                    add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_remaining_col"].Value = 0.ToString("G4") + " (#" + CurrentStoreID.ToString() + ")";
                }

                Remainder[] query_toarray = query.ToArray();
                if (query_toarray.Length > 0)
                {
                    add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_initial_price_col.Index].Value = query_toarray[0].buy_price.ToString("G4") + " (#" + query_toarray[0].storehouse_id.ToString() + ")";
                }
            }

            if (add_remainders_list.Columns[sell_rem_pack_price_col.Index].Index == e.ColumnIndex && null != add_remainders_list.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
            {
                if (null != add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_capacity_col.Index].Value)
                {
                    decimal entered_capacity   = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_capacity_col.Index].Value.ToString());
                    decimal entered_pack_price = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_pack_price_col.Index].Value.ToString());
                    add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_piece_price_col.Index].Value = entered_pack_price / entered_capacity;
                }
            }

            if (add_remainders_list.Columns[sell_rem_piece_price_col.Index].Index == e.ColumnIndex && null != add_remainders_list.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
            {
                if (null != add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_capacity_col.Index].Value)
                {
                    decimal entered_capacity    = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_capacity_col.Index].Value.ToString());
                    decimal entered_piece_price = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_piece_price_col.Index].Value.ToString());
                    add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_pack_price_col.Index].Value = entered_piece_price * entered_capacity;
                }
            }

            try
            {
                if (null != add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_piece_count_col.Index].Value)
                {
                    if (null != add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_count_type_col"].Value)
                    {
                        if ("ცალობით" == add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_count_type_col"].Value.ToString())
                        {
                            decimal piece_price   = 0.0m;
                            decimal row_sum_price = 0.0m;
                            decimal piece_count   = 0.0m;
                            if (null != add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_piece_count_col.Index].Value)
                            {
                                piece_count = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_piece_count_col.Index].Value.ToString());
                            }
                            if (null != add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_piece_price_col"].Value)
                            {
                                piece_price   = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_piece_price_col"].Value.ToString());
                                row_sum_price = piece_count * piece_price;
                                add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_sum_price_col"].Value = row_sum_price; // * ((decimal)add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_storeid_col.Index].Value + (decimal)add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_piece_price_col"].Value);
                                Row_Pricing[e.RowIndex] = row_sum_price;
                                UpdateSumPrice();
                            }
                        }
                        else
                        {
                            decimal pack_count    = 0.0m;
                            decimal piece_price   = 0.0m;
                            decimal row_sum_price = 0.0m;
                            decimal piece_count   = 0.0m;
                            if (null != add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_piece_count_col.Index].Value)
                            {
                                piece_count = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_piece_count_col.Index].Value.ToString());
                            }
                            if (null != add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_piece_price_col"].Value && null != add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_capacity_col"].Value)
                            {
                                piece_price   = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_piece_price_col"].Value.ToString());
                                pack_count    = ParseDecimal(add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_capacity_col"].Value.ToString());
                                row_sum_price = piece_count * pack_count * piece_price;
                                add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_sum_price_col"].Value = row_sum_price; // * ((decimal)add_remainders_list.Rows[e.RowIndex].Cells[sell_rem_storeid_col.Index].Value + (decimal)add_remainders_list.Rows[e.RowIndex].Cells["sell_rem_piece_price_col"].Value);
                                Row_Pricing[e.RowIndex] = row_sum_price;
                                UpdateSumPrice();
                            }
                        }
                    }
                }
            }
            catch (FormatException)
            {
                status_bar_lbl.Text = "შეავსეთ ველები შესაბამისი ფორმატით. ";
            }
            catch (NullReferenceException)//not needed
            {
                status_bar_lbl.Text = "ყველა ველი არაა შევსებული. ";
            }
        }