private void btn_remove_Click(object sender, EventArgs e) { if (dgv_subUnits.Rows.Count > 0) { int id = Convert.ToInt32(dgv_subUnits.CurrentRow.Cells[1].Value.ToString()); unit_relation = db.unites_relations.Where(u => u.id == id).FirstOrDefault(); db.unites_relations.DeleteOnSubmit(unit_relation); db.SubmitChanges(); id = Convert.ToInt32(dgvItems.CurrentRow.Cells[0].Value.ToString()); item = db.items.Where(s => s.id == id).FirstOrDefault(); GetData(); Cmb_unites.SelectedValue = db.unites_relations.Where(s => s.item_id == item.id).Where(r => r.ratio == 1).FirstOrDefault().sup_unit; var i = (from a in db.unites_relations.Where(x => x.ratio > 1).Where(x => x.item_id == item.id) join b in db.unites on a.sup_unit equals b.id select new { a.id, a.sup_unit, الوحدة = b.name, عدد_الوحدات = a.ratio } ).ToList(); dgv_subUnits.DataSource = i; dgv_subUnits.Columns[0].Visible = false; dgv_subUnits.Columns[1].Visible = false; } }
private void button1_Click(object sender, EventArgs e) { if (item.id == 0) { MessageBox.Show("يجب حفظ الصنف اولاً قبل اضافة اي وحدات"); return; } if (Cmb_subUnit.SelectedValue == null) { MessageBox.Show("الرجاء اختيار وحدة"); return; } if (ratio.Value <= 0) { MessageBox.Show("عدد الوحدات لا يمكن ان يكون اقل من او يساوي الصفر"); } int unit_id = Convert.ToInt32(Cmb_subUnit.SelectedValue); foreach (DataGridViewRow row in dgv_subUnits.Rows) { if (Convert.ToInt32(row.Cells[1].Value) == unit_id) { MessageBox.Show("هذه الوحدة مضافة بالفعل"); return; } } string unit_name = Cmb_subUnit.Text.ToString(); unit_relation = new DAL.unites_relation(); unit_relation.item_id = item.id; unit_relation.sup_unit = Convert.ToInt32(Cmb_subUnit.SelectedValue.ToString()); unit_relation.ratio = Convert.ToInt32(ratio.Value.ToString()); db.unites_relations.InsertOnSubmit(unit_relation); db.SubmitChanges(); int id = item.id; item = db.items.Where(s => s.id == id).FirstOrDefault(); GetData(); Cmb_unites.SelectedValue = db.unites_relations.Where(s => s.item_id == item.id).Where(r => r.ratio == 1).FirstOrDefault().sup_unit; var i = (from a in db.unites_relations.Where(x => x.ratio > 1).Where(x => x.item_id == item.id) join b in db.unites on a.sup_unit equals b.id select new { a.id, a.sup_unit, الوحدة = b.name, عدد_الوحدات = a.ratio } ).ToList(); dgv_subUnits.DataSource = i; dgv_subUnits.Columns[1].Visible = false; }
void New() { item = new DAL.item(); unit_relation = new DAL.unites_relation(); DataTable dt = new DataTable(); dgv_subUnits.Columns[0].Visible = false; GetData(); dtt.Clear(); dgvMvt.DataSource = null; dgv_subUnits.DataSource = null; }
void refreshItems() { var i = (from a in db.items from c in db.unites_relations.Where(x => x.ratio == 1).Where(x => x.item_id == a.id) join b in db.stores on a.store_id equals b.id join d in db.unites on c.sup_unit equals d.id select new { id = a.id, الاسم = a.name, الوحدة = d.name, المخزن = b.name, حد_الطلب = a.requestLimit, دولاب = a.locker, صف = a.row, رف = a.cell } ).ToList(); dgvItems.DataSource = i; dgvItems.Columns[0].Visible = false; foreach (DataGridViewRow r in dgvItems.Rows) { decimal In = 0; decimal Out = 0; decimal initial = 0; item2 = db.items.Where(t => t.id == Convert.ToInt32(r.Cells[0].Value.ToString())).FirstOrDefault(); if (item2.movements.Where(cc => cc.movements_header.type == "وارد").Count() > 0) { In = db.movements.Where(cc => cc.item_id == item2.id).Where(cc => cc.movements_header.type == "وارد").Sum(a => a.qty); } if (item2.movements.Where(cc => cc.movements_header.type == "إفتتاحي").Count() > 0) { initial = db.movements.Where(cc => cc.item_id == item2.id).Where(cc => cc.movements_header.type == "إفتتاحي").Sum(a => a.qty); } if (item2.movements.Where(cc => cc.movements_header.type == "صادر").Count() > 0) { Out = db.movements.Where(cc => cc.item_id == item2.id).Where(cc => cc.movements_header.type == "صادر").Sum(a => a.qty); } if (((In + initial) - Out) <= item2.requestLimit) { r.DefaultCellStyle.BackColor = Color.Red; } } }
private void btnDelete_Click(object sender, EventArgs e) { if (dgvItems.Rows.Count > 0) { if (dgvItems.SelectedRows != null) { int id = Convert.ToInt32(dgvItems.CurrentRow.Cells[0].Value.ToString()); item = db.items.Where(u => u.id == id).FirstOrDefault(); if (item.movements.Count > 0) { MessageBox.Show("لا يمكن حذف الصنف حيث تم استخدامه في ععمليات من قبل ومسحه سيؤدي لتلف بعض البيانات"); return; } db.items.DeleteOnSubmit(item); db.SubmitChanges(); refreshItems(); New(); btnDelete.Enabled = false; } } }
private void dgvItems_CellClick_1(object sender, DataGridViewCellEventArgs e) { btnDelete.Enabled = true; int id = 0; if (dgvItems.CurrentRow != null) { id = Convert.ToInt32(dgvItems.CurrentRow.Cells[0].Value.ToString()); item = db.items.Where(s => s.id == id).FirstOrDefault(); GetData(); Cmb_unites.SelectedValue = db.unites_relations.Where(s => s.item_id == item.id).Where(r => r.ratio == 1).FirstOrDefault().sup_unit; var i = (from a in db.unites_relations.Where(x => x.ratio > 1).Where(x => x.item_id == item.id) join b in db.unites on a.sup_unit equals b.id select new { a.id, a.sup_unit, الوحدة = b.name, عدد_الوحدات = a.ratio } ).ToList(); dgv_subUnits.DataSource = i; dgv_subUnits.Columns[0].Visible = false; dgv_subUnits.Columns[1].Visible = false; dgv_subUnits.Columns[2].Visible = false; var m = (from a in db.movements.Where(mv => mv.item_id == id).Where(s => s.movements_header.approved > 0) join v in db.stores on a.movements_header.store_id equals v.id orderby a.movements_header.type select new { رقم_الإذن = a.movements_header.id, الكمية = a.qty, المخزن = v.name, النوع = a.movements_header.type } ).ToList(); dgvMvt.DataSource = m; if (item.movements.Count > 0) { decimal In = 0; decimal Out = 0; decimal initial = 0; if (item.movements.Where(cc => cc.movements_header.type == "وارد").Where(s => s.movements_header.approved > 0).Count() > 0) { In = db.movements.Where(cc => cc.item_id == item.id).Where(cc => cc.movements_header.type == "وارد").Where(s => s.movements_header.approved > 0).Sum(a => a.qty); } if (item.movements.Where(cc => cc.movements_header.type == "إفتتاحي").Where(s => s.movements_header.approved > 0).Count() > 0) { initial = db.movements.Where(cc => cc.item_id == item.id).Where(cc => cc.movements_header.type == "إفتتاحي").Where(s => s.movements_header.approved > 0).Sum(a => a.qty); } if (item.movements.Where(cc => cc.movements_header.type == "صادر").Where(s => s.movements_header.approved > 0).Count() > 0) { Out = db.movements.Where(cc => cc.item_id == item.id).Where(cc => cc.movements_header.type == "صادر").Where(s => s.movements_header.approved > 0).Sum(a => a.qty); } lblQty.Text = ((In + initial) - Out).ToString(); } else { lblQty.Text = "0"; } } }
private void btn_AddItem_Click(object sender, EventArgs e) { if (Cmb_items.SelectedItem == null) { MessageBox.Show("لم يتم اختيار صنف محدد"); return; } if (Cmb_stores.SelectedItem == null) { MessageBox.Show("لم يتم اختيار مخزن محدد"); return; } if (Txt_qty.Value <= 0) { MessageBox.Show("الكمية يجب ان تكون اكبر من صفر"); return; } item = db.items.Where(w => w.id == Convert.ToInt32(Cmb_items.SelectedValue.ToString())).FirstOrDefault(); decimal unit_ratio = item.unites_relations.Where(a => a.sup_unit == Convert.ToInt32(Cmb_unites.SelectedValue.ToString())).FirstOrDefault().ratio; decimal In = 0; decimal Out = 0; decimal old = 0; string item_id = ""; string store_id = ""; string unit_id = ""; decimal qty = 0; if (item.movements.Where(cc => cc.movements_header.type == "وارد").Where(s => s.movements_header.approved > 0).Count() > 0) { In = Convert.ToDecimal(db.movements.Where(cc => cc.item_id == item.id).Where(cc => cc.movements_header.type == "وارد").Where(s => s.movements_header.approved > 0).Sum(a => a.qty)); } if (item.movements.Where(cc => cc.movements_header.type == "صادر").Where(s => s.movements_header.approved > 0).Count() > 0) { Out = db.movements.Where(cc => cc.item_id == item.id).Where(cc => cc.movements_header.type == "صادر").Where(s => s.movements_header.approved > 0).Sum(a => a.qty); } if (item.movements.Where(cc => cc.movements_header.type == "إفتتاحي").Where(s => s.movements_header.approved > 0).Count() > 0) { In += db.movements.Where(cc => cc.item_id == item.id).Where(cc => cc.movements_header.type == "إفتتاحي").Where(s => s.movements_header.approved > 0).Sum(a => a.qty); } decimal qtyExist = (In - Out); if ((Txt_qty.Value * unit_ratio) > qtyExist && Cmb_type.SelectedItem.ToString() == "صادر") { MessageBox.Show("الكمية المطلوبة غير متاحة في المخزن"); return; } foreach (DataGridViewRow row in dgvItems.Rows) { if (row.Cells[3].Value.ToString() == Cmb_items.SelectedValue.ToString()) { DialogResult dialog = MessageBox.Show("تم إضافة هذا الصنف مسبقاً هل تريد تعديل الكمية المضافة", "", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) //yes { item_id = Cmb_items.SelectedValue.ToString(); store_id = Cmb_stores.SelectedValue.ToString(); unit_id = Cmb_unites.SelectedValue.ToString(); qty = Txt_qty.Value; row.Cells[0].Value = dgvItems.Rows.Count; row.Cells["store_id"].Value = store_id; row.Cells["unit_id"].Value = unit_id; row.Cells["item_id"].Value = item_id; row.Cells["item_name"].Value = Cmb_items.Text; row.Cells["unit_name"].Value = Cmb_unites.Text; row.Cells["qty"].Value = qty; row.Cells["unit_qty"].Value = (qty * unit_ratio); return; } else // no { return; } } } item_id = Cmb_items.SelectedValue.ToString(); store_id = Cmb_stores.SelectedValue.ToString(); unit_id = Cmb_unites.SelectedValue.ToString(); qty = Txt_qty.Value; dgvItems.Rows.Add(1); int rowindex = dgvItems.Rows.Count - 1; dgvItems.Rows[rowindex].Cells[0].Value = dgvItems.Rows.Count; dgvItems.Rows[rowindex].Cells["store_id"].Value = store_id; dgvItems.Rows[rowindex].Cells["unit_id"].Value = unit_id; dgvItems.Rows[rowindex].Cells["item_id"].Value = item_id; dgvItems.Rows[rowindex].Cells["item_name"].Value = Cmb_items.Text; dgvItems.Rows[rowindex].Cells["unit_name"].Value = Cmb_unites.Text; dgvItems.Rows[rowindex].Cells["qty"].Value = qty; dgvItems.Rows[rowindex].Cells["unit_qty"].Value = (qty * unit_ratio); }