Exemplo n.º 1
0
        private void TM_BuyRem_Click(object sender, EventArgs e)
        {
            FRM_BuyBillRem bbr = new FRM_BuyBillRem();

            bbr.ShowDialog();
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvBill.Rows.Count > 0)
                {
                    if (int.Parse(txtAmountRem.Text) != 0 && txtSupName.Text.Equals(""))
                    {
                        MessageBox.Show("يجب ادخال اسم المورد لأن المبلغ المدفوع لا يساوي قيمة الفاتورة");
                        return;
                    }
                    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_BuyBillRem bb = new FRM_BuyBillRem();
                        con.Open();
                        OleDbCommand cmd3 = new OleDbCommand("insert into BoxInfo (Proc_type,Proc_Date,Deposit,Withdraw,Discreption)" +
                                                             "values ('مرتجع فاتورة شراء','" + txtDate.Text + "','" + txtAmountPay.Text + "','0','" + 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("هناك خطأ في بيانات الفاتورة المدخلة");
            }
        }