Esempio n. 1
0
 public static void InsertItem(BillDetailed aBillDetailed)
 {
     if (Helper.Instance.con.State == System.Data.ConnectionState.Closed)
     {
         try
         {
             Helper.Instance.con.Open();
             SqlCommand cmd = new SqlCommand("INSERT INTO BillDetailed (ItemID,ItemDescription,Qty,SellPrice,TotalPerUnit,Number,OldAvaQty,OldAvgUnitCost,IsRevised) VALUES (@ItemID,@ItemDescription,@Qty,@SellPrice,@TotalPerUnit,@BillNumber,@OldAvaQty,@OldAvgUnitCost,0)", Helper.Instance.con);
             cmd.Parameters.Add("@ItemID", SqlDbType.Int).Value = aBillDetailed.Bill_Detailed_ItemID;
             cmd.Parameters.Add("@ItemDescription", SqlDbType.NVarChar).Value = aBillDetailed.Bill_Detailed_ItemDescription;
             cmd.Parameters.Add("@Qty", SqlDbType.Float).Value            = aBillDetailed.Bill_Detailed_Qty;
             cmd.Parameters.Add("@SellPrice", SqlDbType.Float).Value      = aBillDetailed.Bill_Detailed_SellPrice;
             cmd.Parameters.Add("@TotalPerUnit", SqlDbType.Float).Value   = aBillDetailed.Bill_Detailed_TotalPerUnit;
             cmd.Parameters.Add("@BillNumber", SqlDbType.Int).Value       = aBillDetailed.Bill_Detailed_Number;
             cmd.Parameters.Add("@OldAvaQty", SqlDbType.Float).Value      = aBillDetailed.Bill_Detailed_OldAvaQty;
             cmd.Parameters.Add("@OldAvgUnitCost", SqlDbType.Float).Value = aBillDetailed.Bill_Detailed_OldAvgUnitCost;
             cmd.ExecuteNonQuery();
             Helper.Instance.con.Close();
         }
         catch (Exception ex)
         {
             Helper.Instance.con.Close();
             MessageBox.Show("ERROR IN BILL DETAILED MGMG (INSERT FUNCTION) EX=" + ex.Message.ToString());
         }
     }
 }
Esempio n. 2
0
        private void Add1000Sale_Click(object sender, EventArgs e)
        {
            int      cnt        = 1;
            DateTime date       = DateTime.Now;
            var      randAmount = new Random();

            int userId = int.Parse(UsersMgmt.SelectAllUsers().Rows[0]["ID"].ToString());

            while (cnt++ < NumberOfBills)
            {
                try
                {
                    int numofDetailed = randAmount.Next(1, 20);
                    var aBillGeneral  = new BillGeneral();
                    aBillGeneral.Bill_General_AccountID       = 1;
                    aBillGeneral.Bill_General_CashIn          = 100;
                    aBillGeneral.Bill_General_Currency        = "JOD";
                    aBillGeneral.Bill_General_CurrencyID      = 1;
                    aBillGeneral.Bill_General_CustomerID      = 1;
                    aBillGeneral.Bill_General_Date            = date.Subtract(TimeSpan.FromDays(randAmount.Next(1, 2000))).ToShortDateString();
                    aBillGeneral.Bill_General_DiscountPerc    = 0;
                    aBillGeneral.Bill_General_IsCashCredit    = 0;
                    aBillGeneral.Bill_General_NetAmount       = 100;
                    aBillGeneral.Bill_General_Number          = BillGeneralMgmt.NextBillNumber();
                    aBillGeneral.Bill_General_PaymentMethodID = 1;
                    aBillGeneral.Bill_General_PriceLevel      = 1;
                    aBillGeneral.Bill_General_SalesDiscount   = 0;
                    aBillGeneral.Bill_General_SubTotal        = 100;
                    aBillGeneral.Bill_General_TellerID        = userId;
                    aBillGeneral.Bill_General_Time            =
                        DateTime.Now.ToShortTimeString();
                    aBillGeneral.Bill_General_TotalCost      = randAmount.Next(50, 99);
                    aBillGeneral.Bill_General_TotalDiscount  = 0;
                    aBillGeneral.Bill_General_TotalItems     = numofDetailed;
                    aBillGeneral.Bill_General_TotalPrice     = 100;
                    aBillGeneral.Bill_General_TotalTax       = 16;
                    aBillGeneral.CustomerAccountAmountOld    = 0;
                    aBillGeneral.Bill_General_Comments       = "Test Sale";
                    aBillGeneral.Bill_General_CreditCardInfo = "NotCredit";

                    Random aRandom = new Random();

                    if (BillGeneralMgmt.InsertBill(aBillGeneral))
                    {
                        while (numofDetailed > 0)
                        {
                            BillDetailed aBillDetailed = new BillDetailed();
                            string       aBarcode      = "Test Item " + aRandom.Next(1, (int)NumberOfItems);
                            DataTable    aItemRow      = ItemsMgmt.SelectItemByBarCode(aBarcode);
                            if (aItemRow.Rows.Count != 0)
                            {
                                aBillDetailed.Bill_Detailed_ItemDescription = aItemRow.Rows[0]["Description"].ToString();
                                aBillDetailed.Bill_Detailed_ItemID          = int.Parse(aItemRow.Rows[0]["ID"].ToString());
                                aBillDetailed.Bill_Detailed_Number          = aBillGeneral.Bill_General_Number;
                                aBillDetailed.Bill_Detailed_OldAvaQty       = double.Parse(aItemRow.Rows[0]["Qty"].ToString());
                                aBillDetailed.Bill_Detailed_OldAvgUnitCost  =
                                    double.Parse(aItemRow.Rows[0]["AvgUnitCost"].ToString());
                                aBillDetailed.Bill_Detailed_Qty       = numofDetailed;
                                aBillDetailed.Bill_Detailed_SellPrice = double.Parse(aItemRow.Rows[0]["SellPrice"].ToString());

                                aBillDetailed.Bill_Detailed_TotalPerUnit = aBillDetailed.Bill_Detailed_Qty *
                                                                           aBillDetailed.Bill_Detailed_SellPrice;

                                BillDetailedMgmt.InsertItem(aBillDetailed);
                            }
                            numofDetailed--;
                        }
                    }
                    if (cnt % 100 == 0)
                    {
                        label1.Text = $"Adding Bill {cnt}/{NumberOfBills} ... ({(cnt / NumberOfBills) * 100 })%";
                        Application.DoEvents();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Error in {cnt} \n {ex}");
                }
            }
        }