Exemplo n.º 1
0
        private void تعديلالفاتورةToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ContractSales conFrm = new ContractSales();

            BL.ProfitsClass pr = new BL.ProfitsClass();
            DataTable       d  = new DataTable();

            d = con.GetDetailsByOrderID(Convert.ToInt32(this.dataGridView1.CurrentRow.Cells[0].Value.ToString()));
            conFrm.ConID.Text     = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            conFrm.Con_date.Value = (DateTime)this.dataGridView1.CurrentRow.Cells[1].Value;
            conFrm.Con_user.Text  = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
            conFrm.ConNote.Text   = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
            conFrm.custId.Text    = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
            conFrm.Total.Text     = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
            if (this.dataGridView1.CurrentRow.Cells[7].Value.ToString() != string.Empty)
            {
                conFrm.debit.Text = this.dataGridView1.CurrentRow.Cells[7].Value.ToString();
                conFrm.paid.Text  = Convert.ToString(Convert.ToDouble(this.dataGridView1.CurrentRow.Cells[6].Value.ToString()) - Convert.ToDouble(this.dataGridView1.CurrentRow.Cells[7].Value.ToString()));
            }
            conFrm.PricePrev = Convert.ToDouble(pr.GetProfitPeforeUpdating(Convert.ToInt32(this.dataGridView1.CurrentRow.Cells[0].Value.ToString())).Rows[0][0].ToString());

            conFrm.dataGridView1.DataSource = d;
            conFrm.Text                 = " :تحديث بيانات الفاتورة المحددة " + this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            conFrm.SaveSale.Text        = "تحديث";
            conFrm.ConState             = "edit";
            conFrm.newSale.Enabled      = false;
            conFrm.Print.Enabled        = false;
            conFrm.choosebtn.Enabled    = false;
            conFrm.CustChoosBtn.Enabled = false;
            conFrm.SetDatatableForUpdate(d);
            conFrm.SaveSale.Enabled = true;
            // conFrm.paid.ReadOnly = true;
            conFrm.حذفالسطرالحاليToolStripMenuItem.Enabled = false;
            conFrm.حذفالكلToolStripMenuItem.Enabled        = false;

            conFrm.ShowDialog();
            if (conFrm.closed)
            {
                this.dataGridView1.DataSource         = con.SearchOrders(textSearch.Text);
                this.dataGridView1.Columns[2].Visible = false;
            }
        }
Exemplo n.º 2
0
        private void SaveSale_Click(object sender, EventArgs e)
        {
            if (ConID.Text == string.Empty)
            {
                MessageBox.Show(" رقم الفاتورة غير موجود  ", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                newSale.Focus();
                return;
            }
            if (ConNote.Text == string.Empty)
            {
                MessageBox.Show(" ادخل وصف للفاتورة  ", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ConNote.Focus();
                return;
            }

            if (custId.Text == string.Empty)
            {
                MessageBox.Show(" رقم الزبون غير موجود  ", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CustChoosBtn.Focus();
                return;
            }
            if (dataGridView1.Rows.Count <= 1)
            {
                MessageBox.Show(" لايوجد بيانات مدخلة لبيعها  ", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                choosebtn.Focus();
                return;
            }
            if (Total.Text == string.Empty || Total.Text == "0")
            {
                MessageBox.Show(" تحقق من البيانات! لايوجد مجموع!  ", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                choosebtn.Focus();
                return;
            }

            if (Convert.ToDouble(Total.Text) < 0)
            {
                MessageBox.Show("لايمكن أن يكون المجموع سالباً   ", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                choosebtn.Focus();
                return;
            }
            if (Convert.ToDouble(paid.Text) > Convert.ToDouble(Total.Text))
            {
                MessageBox.Show("لايمكن ان يكون النقد أكبر من المجموع  ", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                paid.Focus();
                paid.SelectionStart  = 0;
                paid.SelectionLength = paid.Text.Length;
            }
            if (Convert.ToDouble(debit.Text) > Convert.ToDouble(Total.Text))
            {
                MessageBox.Show("لايمكن ان يكون الآجل أكبر من المجموع  ", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                paid.Focus();
                paid.SelectionStart  = 0;
                paid.SelectionLength = paid.Text.Length;
            }

            /////////// add Contract
            if (ConState == "add")
            {
                if (MessageBox.Show("? هل تريد الحفظ", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    if (id.Text == string.Empty && label.Text == string.Empty)
                    {
                        try
                        {
                            // VAlue gives a type Date
                            //aDD_oRDER
                            con.Add_Order(Convert.ToInt32(ConID.Text), ConNote.Text,
                                          Con_date.Value, Con_user.Text, Convert.ToInt32(custId.Text), Convert.ToDouble(Total.Text), Convert.ToDouble(debit.Text));
                            // ADD ORDER dETAILS
                            for (int i = 0; i < this.dataGridView1.Rows.Count - 1; i++)
                            {
                                con.OrderDetails(this.dataGridView1.Rows[i].Cells[0].Value.ToString()
                                                 , Convert.ToInt32(ConID.Text), Convert.ToInt32(this.dataGridView1.Rows[i].Cells[3].Value.ToString()), this.dataGridView1.Rows[i].Cells[2].Value.ToString()
                                                 , Convert.ToDouble(this.dataGridView1.Rows[i].Cells[5].Value.ToString()), this.dataGridView1.Rows[i].Cells[4].Value.ToString()
                                                 , this.dataGridView1.Rows[i].Cells[6].Value.ToString());
                                /// Add To Log
                                con.OrderDetailsLog(Con_date.Value, Convert.ToInt32(ConID.Text), this.dataGridView1.Rows[i].Cells[0].Value.ToString()
                                                    , Convert.ToInt32(this.dataGridView1.Rows[i].Cells[3].Value.ToString()), this.dataGridView1.Rows[i].Cells[2].Value.ToString()
                                                    , Convert.ToDouble(this.dataGridView1.Rows[i].Cells[5].Value.ToString()), this.dataGridView1.Rows[i].Cells[4].Value.ToString()
                                                    , this.dataGridView1.Rows[i].Cells[6].Value.ToString(), "الأصل");
                            }
                            /// Add Profits To Profit

                            BL.ProfitsClass pro    = new BL.ProfitsClass();
                            int             profId = Convert.ToInt32(pro.GetLastProfitsId().Rows[0][0].ToString());
                            pro.AddProfit(profId, this.Con_date.Value, Convert.ToDouble(paid.Text), Convert.ToInt32(custId.Text), Convert.ToInt32(ConID.Text), ConNote.Text);

                            //add DEbit
                            BL.DebitsClass deb   = new BL.DebitsClass();
                            int            debId = Convert.ToInt32(deb.GetLastDebitId().Rows[0][0].ToString());
                            deb.AddDebit(debId, this.Con_date.Value, Convert.ToDouble(debit.Text), Convert.ToInt32(custId.Text), Convert.ToInt32(ConID.Text), ConNote.Text);



                            MessageBox.Show("تمت العملية بنجاح", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            ClearData();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString() + " أخفقت العملية ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show(" عذراُ لايمكنك الحفظ .. هناك بيانات لم يتم حفظها ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    return;
                }
            }
            //// update
            else
            {
                if (MessageBox.Show("? هل تريد التعديل", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {
                        if (id.Text == string.Empty && label.Text == string.Empty)
                        {
                            // VAlue gives a type Date
                            //update_oRDER
                            con.Update_Order(Convert.ToInt32(ConID.Text), Con_date.Value, ConNote.Text,
                                             Convert.ToInt32(custId.Text), Convert.ToDouble(Total.Text), Convert.ToDouble(debit.Text));
                            // update ORDER dETAILS

                            for (int i = 0; i < this.dataGridView1.Rows.Count - 1; i++)
                            {
                                int QtyAfterUpdates = updateQty - Convert.ToInt32(this.dataGridView1.Rows[i].Cells[3].Value.ToString());
                                con.UpdateOrderDetails(this.dataGridView1.Rows[i].Cells[0].Value.ToString()
                                                       , Convert.ToInt32(ConID.Text), Convert.ToInt32(this.dataGridView1.Rows[i].Cells[3].Value.ToString()), this.dataGridView1.Rows[i].Cells[2].Value.ToString()
                                                       , Convert.ToDouble(this.dataGridView1.Rows[i].Cells[5].Value.ToString()), this.dataGridView1.Rows[i].Cells[4].Value.ToString()
                                                       , this.dataGridView1.Rows[i].Cells[6].Value.ToString(), QtyAfterUpdates);
                                /// Add To Log
                                con.OrderDetailsLog(DateTime.Now, Convert.ToInt32(ConID.Text), this.dataGridView1.Rows[i].Cells[0].Value.ToString()
                                                    , Convert.ToInt32(this.dataGridView1.Rows[i].Cells[3].Value.ToString()), this.dataGridView1.Rows[i].Cells[2].Value.ToString()
                                                    , Convert.ToDouble(this.dataGridView1.Rows[i].Cells[5].Value.ToString()), this.dataGridView1.Rows[i].Cells[4].Value.ToString()
                                                    , this.dataGridView1.Rows[i].Cells[6].Value.ToString(), "معدل");
                            }

                            /// update Profits To Profit

                            BL.ProfitsClass pro = new BL.ProfitsClass();
                            //  double PrevPrice = Convert.ToDouble(pro.GetProfitPeforeUpdating(Convert.ToInt32(ConID.Text)).Rows[0][0].ToString());
                            pro.UpdateProfit(this.Con_date.Value, Convert.ToDouble(paid.Text), Convert.ToInt32(ConID.Text), ConNote.Text);

                            //update DEbit
                            BL.DebitsClass deb   = new BL.DebitsClass();
                            int            debId = Convert.ToInt32(deb.GetLastDebitId().Rows[0][0].ToString());
                            deb.UpdateDepit(this.Con_date.Value, Convert.ToDouble(debit.Text), Convert.ToInt32(custId.Text), Convert.ToInt32(ConID.Text), ConNote.Text, PricePrev);



                            MessageBox.Show("تمت العملية بنجاح", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            ClearData();
                        }
                        else
                        {
                            MessageBox.Show(" عذراُ لايمكنك الحفظ .. هناك بيانات لم يتم حفظها ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString() + " أخفقت العملية ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    return;
                }
            }
        }