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; } } }