Esempio n. 1
0
        private void TM_BBill_Click(object sender, EventArgs e)
        {
            FRM_BuyBill bb = new FRM_BuyBill();

            bb.ShowDialog();
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                double           Deposit  = 0;
                double           Withdraw = 0;
                double           amount   = 0;
                OleDbDataAdapter daBox    = new OleDbDataAdapter("select Deposit,Withdraw from BoxInfo ", con);
                DataTable        dtbox    = new DataTable();
                daBox.Fill(dtbox);
                for (int i = 0; i < dtbox.Rows.Count; i++)
                {
                    Deposit  += double.Parse(dtbox.Rows[i][0].ToString());
                    Withdraw += double.Parse(dtbox.Rows[i][1].ToString());
                }
                amount = (Deposit - Withdraw);
                //MessageBox.Show(amount.ToString());

                if (dgvBill.Rows.Count > 0)
                {
                    if (int.Parse(txtAmountRem.Text) != 0 && txtSupName.Text.Equals(""))
                    {
                        MessageBox.Show("يجب ادخال اسم المورد لأن المبلغ المدفوع لا يساوي قيمة الفاتورة");
                        return;
                    }
                    else
                    {
                        if (double.Parse(txtAmountPay.Text) > amount)
                        {
                            MessageBox.Show("لا يمكن إتمام العملية .. لأن المبلغ المدفوع أكبر من رصيد الصندوق");
                        }
                        else
                        {
                            con.Open();
                            OleDbCommand cmd = new OleDbCommand("insert into Buy_Bill (Date_B_Bill,Total,Sup_Name,Discount,Description,Buyer_N,B_AmountPay,B_AmountRem)" +
                                                                "values ('" + txtDate.Text + "','" + txtTotal.Text + "','" + txtSupName.Text + "','" + txtDiscount.Text + "','" + txtDiscription.Text + "'," +
                                                                "'" + txtBuyerN.Text + "','" + txtAmountPay.Text + "','" + txtAmountRem.Text + "')", con);
                            cmd.ExecuteNonQuery();
                            con.Close();


                            string           LastIDBill = "";
                            OleDbDataAdapter da         = new OleDbDataAdapter("select TOP 1 B_Bill_ID from Buy_Bill ORDER BY B_Bill_ID DESC", con);
                            DataTable        dt         = new DataTable();
                            da.Fill(dt);
                            LastIDBill = dt.Rows[0][0].ToString();


                            DataTable dt1 = new DataTable();
                            dt1.Columns.Add("P_ID");
                            dt1.Columns.Add("Pro_name");
                            dt1.Columns.Add("Cat_Name");
                            dt1.Columns.Add("Buy_Price");
                            dt1.Columns.Add("Qty");
                            for (int ii = 0; ii < dgvBill.Rows.Count; ii++)
                            {
                                dt1.Rows.Add(dgvBill.Rows[ii].Cells[0].Value.ToString(), dgvBill.Rows[ii].Cells[1].Value.ToString(), dgvBill.Rows[ii].Cells[2].Value.ToString(), dgvBill.Rows[ii].Cells[3].Value.ToString(), dgvBill.Rows[ii].Cells[4].Value.ToString());
                            }


                            for (int i = 0; i < dgvBill.Rows.Count; i++)
                            {
                                OleDbDataAdapter daq = new OleDbDataAdapter("select Qty from Product where Pro_ID = " + dt1.Rows[i][0].ToString() + "", con);
                                DataTable        dtq = new DataTable();
                                daq.Fill(dtq);
                                string qty = Convert.ToString(int.Parse(dtq.Rows[0][0].ToString()) + int.Parse(dt1.Rows[i][4].ToString()));
                                con.Open();
                                OleDbCommand cmd4 = new OleDbCommand("update Product set Qty= " + qty + " where Pro_ID = " + dt1.Rows[i][0].ToString() + "", con);
                                cmd4.ExecuteNonQuery();
                                con.Close();

                                con.Open();
                                OleDbCommand cmd1 = new OleDbCommand("insert into B_D_Bill (Pro_Name,Qty,B_Price,B_Bill_ID)" +
                                                                     "values ('" + dt1.Rows[i][1].ToString() + "','" + dt1.Rows[i][4].ToString() + "','" + dt1.Rows[i][3].ToString() + "'," + LastIDBill + ")", con);
                                cmd1.ExecuteNonQuery();
                                con.Close();
                            }


                            if (int.Parse(txtAmountRem.Text) > 0)
                            {
                                con.Open();
                                OleDbCommand cmd2 = new OleDbCommand("insert into Sup_Account (Sup_A_Am,B_Bill_ID,Sup_Name)" +
                                                                     "values ('" + txtAmountRem.Text + "'," + LastIDBill + ",'" + txtSupName.Text + "')", con);
                                cmd2.ExecuteNonQuery();
                                con.Close();
                            }

                            FRM_BuyBill bb = new FRM_BuyBill();
                            con.Open();
                            OleDbCommand cmd3 = new OleDbCommand("insert into BoxInfo (Proc_type,Proc_Date,Deposit,Withdraw,Discreption)" +
                                                                 "values ('فاتورة شراء','" + txtDate.Text + "','0','" + txtAmountPay.Text + "','" + bb.Text + "')", con);
                            cmd3.ExecuteNonQuery();
                            con.Close();

                            btnSave.Enabled      = btnDelete.Enabled = btnUpdate.Enabled = btnCancel.Enabled = btnChoPro.Enabled = btnChoSup.Enabled = false;
                            txtDiscount.ReadOnly = txtAmountPay.ReadOnly = txtQty.ReadOnly = txtDiscription.ReadOnly = true;



                            MessageBox.Show("تمت عملية حفظ بيانات الفاتورة بنجاح");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("لا يوجد أي منتج في الفاتورة");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("هناك خطأ في بيانات الفاتورة المدخلة");
            }
        }