private void dgrd_OrderLines_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1 && e.ColumnIndex == dgrd_OrderLines.Columns["ProductName"].Index) { BDProductPrimaryKey pk = new BDProductPrimaryKey(); pk.ProductID = Convert.ToInt32(dgrd_OrderLines.Rows[e.RowIndex].Cells["ProductName"].Value); BDProduct _product = _productWrapper.SelectOne(pk); dgrd_OrderLines.Rows[e.RowIndex].Cells["IsAcceptBatch"].Value = _product.IsAcceptBatch; if (_product.IsAcceptBatch == true) { dgrd_OrderLines.Rows[e.RowIndex].Cells["BatchNumber"].ReadOnly = false; dgrd_OrderLines.Rows[e.RowIndex].Cells["ExpiryDate"].ReadOnly = false; } else { dgrd_OrderLines.Rows[e.RowIndex].Cells["BatchNumber"].ReadOnly = true; dgrd_OrderLines.Rows[e.RowIndex].Cells["ExpiryDate"].ReadOnly = true; } } if (e.RowIndex != -1 && e.ColumnIndex == dgrd_OrderLines.Columns["TotalQty"].Index || e.RowIndex != -1 && e.ColumnIndex == dgrd_OrderLines.Columns["PurchasePrice"].Index) { CalculateTotal(); } }
private void initEntity(int productId) { try { BDProductPrimaryKey pk = new BDProductPrimaryKey(); pk.ProductID = productId; _bdProduct = _bdProductWrapper.SelectOne(pk); loadUI(); } catch (Exception ex) { throw; } }
private void initEntity(int productId) { try { BDProductPrimaryKey pk = new BDProductPrimaryKey(); pk.ProductID = productId; _bdProduct = _bdProductWrapper.SelectOne(pk); loadUI(); } catch (Exception ex) { MessageBox.Show("حدث خطأ برجاء تكرار العمليه مره اخرى واذا تكرر الخطا برجاءالاتصال بالشخص المصمم للبرنامج وارسال رسالة الخطا التى ستظهر بعد قليل له"); MessageBox.Show(ex.Message); } }
new private bool Validate() { bool isValid = false; bool isValidProduct = false; int ProductID = 0; int? oldStockTypeId = dgrid_stock.SelectedRows.Count > 0 ? int.Parse(dgrid_stock.SelectedRows[0].Cells["col_StockTypeID"].Value.ToString()) : 0; string BatchID = dgrid_batches.SelectedRows.Count > 0 ? dgrid_batches.SelectedRows[0].Cells["col_batch"].Value.ToString() : ""; DateTime?ExpiryDate = dgrid_batches.SelectedRows.Count > 0 ? Convert.ToDateTime(dgrid_batches.SelectedRows[0].Cells["col_expiry"].Value.ToString()) : (DateTime?)null; decimal oldQty = dgrid_batches.SelectedRows.Count > 0 ? Convert.ToDecimal(dgrid_batches.SelectedRows[0].Cells["col_batchQty"].Value.ToString()) : Convert.ToDecimal(dgrid_stock.SelectedRows[0].Cells["col_qty"].Value.ToString()); int AdjustReasonID = 0; int StockTypeID = 0; int InventoryID = 0; decimal Qty = num_Qty.Value; int.TryParse(dgrid_stock.SelectedRows[0].Cells["col_invProductStock"].Value.ToString(), out ProductID); int.TryParse(cbx_AdjustReason.SelectedValue.ToString(), out AdjustReasonID); int.TryParse(cbx_StockTypeTO.SelectedValue.ToString(), out StockTypeID); int.TryParse(cbx_Store.SelectedValue.ToString(), out InventoryID); if (ProductID > 0) { isValidProduct = true; BDProductPrimaryKey pk = new BDProductPrimaryKey(); pk.ProductID = ProductID; if (_ProductWrapper.SelectOne(pk).IsAcceptBatch == true) { isValidProduct = (!string.IsNullOrEmpty(BatchID) && ExpiryDate.HasValue); } } if (!isValidProduct || AdjustReasonID == 0 || StockTypeID == 0 || InventoryID == 0 || Qty == 0 || Qty > oldQty || oldStockTypeId == StockTypeID) { isValid = false; } else { isValid = true; if (_isEdit) { INVAdjustStock _EditNewAdjustStock = _adjustStock; _EditNewAdjustStock.Qty *= -1; _adjustStockCollection.Add(_EditNewAdjustStock); INVAdjustStock _EditOldAdjustStock = _adjustStock; _adjustStock.StockTypeID = _adjustStock.OldStockTypeID; _adjustStockCollection.Add(_EditOldAdjustStock); } _adjustStock.ProductID = ProductID; _adjustStock.AdjustReasonID = AdjustReasonID; _adjustStock.AdjustStockID = _adjustStockID; _adjustStock.BatchID = null; _adjustStock.InventoryID = InventoryID; _adjustStock.StockTypeID = StockTypeID; _adjustStock.OldStockTypeID = oldStockTypeId; _adjustStock.Qty = Qty; _adjustStock.BatchNumber = BatchID; _adjustStock.ExpiryDate = ExpiryDate; if (_isEdit) { _adjustStock.UpdateDate = DateTime.Now; _adjustStock.UpdatedBy = GlobalVariables.CurrentUser.UserID; } else { _adjustStock.CredateDate = DateTime.Now; _adjustStock.CreatedBy = GlobalVariables.CurrentUser.UserID; } INVAdjustStock _oldAdjustStock = new INVAdjustStock(); _oldAdjustStock.ProductID = ProductID; _oldAdjustStock.AdjustReasonID = AdjustReasonID; _oldAdjustStock.AdjustStockID = _adjustStockID; _oldAdjustStock.BatchID = null; _oldAdjustStock.InventoryID = InventoryID; _oldAdjustStock.StockTypeID = oldStockTypeId; _oldAdjustStock.Qty = (-1 * Qty); _oldAdjustStock.BatchNumber = BatchID; _oldAdjustStock.ExpiryDate = ExpiryDate; if (_isEdit) { _oldAdjustStock.UpdateDate = DateTime.Now; _oldAdjustStock.UpdatedBy = GlobalVariables.CurrentUser.UserID; } else { _oldAdjustStock.CredateDate = DateTime.Now; _oldAdjustStock.CreatedBy = GlobalVariables.CurrentUser.UserID; } _adjustStockCollection.Add(_oldAdjustStock); } return(isValid); }
private void dgrd_ReturnOrderLines_CellValueChanged(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (e.RowIndex != -1 && e.ColumnIndex == senderGrid.Columns["TotalQty"].Index && !string.IsNullOrEmpty(senderGrid.Rows[e.RowIndex].Cells["TotalQty"].Value.ToString())) { if (Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value) == -1) { MessageBox.Show("أختر صنف أولا"); return; } VSALSalesOrder vSALSalesOrder = vSALSalesOrderCollection.Where(a => a.ProductID == Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value)).SingleOrDefault(); if (vSALSalesOrder == null) { MessageBox.Show("هذا الصنف غير موجود بالفاتورة الاصليه"); senderGrid.Rows[e.RowIndex].ErrorText = "هذا الصنف غير موجود بالفاتورة الاصليه"; senderGrid.Rows[e.RowIndex].Cells["ProductName"].Style.BackColor = Color.Red; return; } //else //{ // if ((sALSalesReturnLineCollection.Where(a => a.OriginalSalesLineID == vSALSalesOrder.SalesLineID).ToList().Count) == 0) // sALSalesReturnLineCollection.Add(new SALSalesReturnLine() // { // OriginalSalesLineID = vSALSalesOrder.SalesLineID, // Qty = (decimal)senderGrid.Rows[e.RowIndex].Cells["TotalQty"].Value, // BatchNumber = vSALSalesOrder.IsAcceptBatch == true ? senderGrid.Rows[e.RowIndex].Cells["BatchNumber"].Value.ToString() : null, // ExpiryDate = vSALSalesOrder.IsAcceptBatch == true ? Convert.ToDateTime(senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].Value) : (DateTime?)null, // Reason = senderGrid.Rows[e.RowIndex].Cells["Reason"].Value.ToString() // }); // else // { // sALSalesReturnLineCollection.RemoveAt(sALSalesReturnLineCollection.IndexOf(sALSalesReturnLineCollection.Where(a => a.OriginalSalesLineID == vSALSalesOrder.SalesLineID).SingleOrDefault())); // sALSalesReturnLineCollection.Add(new SALSalesReturnLine() // { // OriginalSalesLineID = vSALSalesOrder.SalesLineID, // Qty = (decimal)senderGrid.Rows[e.RowIndex].Cells["TotalQty"].Value, // BatchNumber = vSALSalesOrder.IsAcceptBatch == true ? senderGrid.Rows[e.RowIndex].Cells["BatchNumber"].Value.ToString() : null, // ExpiryDate = vSALSalesOrder.IsAcceptBatch == true ? Convert.ToDateTime(senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].Value) : (DateTime?)null, // Reason = senderGrid.Rows[e.RowIndex].Cells["Reason"].Value.ToString() // }); // } //} tbx_Total.Text = (CalculateTotal((double)senderGrid.Rows[e.RowIndex].Cells["UnitPrice"].Value * (double)senderGrid.Rows[e.RowIndex].Cells["TotalQty"].Value)).ToString(); } if (e.RowIndex != -1 && e.ColumnIndex == senderGrid.Columns["ProductName"].Index) { BDProductPrimaryKey pk = new BDProductPrimaryKey(); pk.ProductID = Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value); BDProduct _product = bDProductWrapper.SelectOne(pk); senderGrid.Rows[e.RowIndex].Cells["IsAcceptBatch"].Value = _product.IsAcceptBatch; if (_product.IsAcceptBatch == true) { senderGrid.Rows[e.RowIndex].Cells["BatchNumber"].ReadOnly = false; senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].ReadOnly = false; } else { senderGrid.Rows[e.RowIndex].Cells["BatchNumber"].ReadOnly = true; senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].ReadOnly = true; } } }
private void dgrd_ReturnOrderLines_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { var senderGrid = (DataGridView)sender; if (e.RowIndex != -1 && (e.ColumnIndex == senderGrid.Columns["TotalQty"].Index /*|| e.ColumnIndex == senderGrid.Columns["UnitPrice"].Index*/) && !string.IsNullOrEmpty(senderGrid.Rows[e.RowIndex].Cells["TotalQty"].Value.ToString())) { if (Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value) == -1) { MessageBox.Show("أختر صنف أولا"); return; } if (Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["StockType"].Value) == -1) { MessageBox.Show("أختر نوع مرتجع أولا"); return; } VSALSalesOrder vSALSalesOrder = vSALSalesOrderCollection.Where(a => a.ProductID == Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value)).SingleOrDefault(); if (Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["TotalQty"].Value) > vSALSalesOrder.TotalQty) { MessageBox.Show("الكمية المرتجعه اكبر من الكميه المدخله فى الفاتوره الاصليه"); return; } if (senderGrid.Rows[e.RowIndex].Cells["UnitPrice"].Value != null && senderGrid.Rows[e.RowIndex].Cells["TotalQty"].Value != null) { tbx_Total.Text = (CalculateTotal(Convert.ToDouble(senderGrid.Rows[e.RowIndex].Cells["UnitPrice"].Value) * Convert.ToDouble(senderGrid.Rows[e.RowIndex].Cells["TotalQty"].Value))).ToString(); } else { return; } } if (e.RowIndex != -1 && e.ColumnIndex == senderGrid.Columns["ProductName"].Index) { VSALSalesOrder vSALSalesOrder = vSALSalesOrderCollection.Where(a => a.ProductID == Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value)).SingleOrDefault(); if (vSALSalesOrder == null) { MessageBox.Show("هذا الصنف غير موجود بالفاتورة الاصليه"); senderGrid.Rows[e.RowIndex].ErrorText = "هذا الصنف غير موجود بالفاتورة الاصليه"; //senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value = null; senderGrid.Rows[e.RowIndex].Cells["ProductName"].Style.BackColor = Color.Red; return; } BDProductPrimaryKey pk = new BDProductPrimaryKey(); pk.ProductID = Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value); BDProduct _product = bDProductWrapper.SelectOne(pk); senderGrid.Rows[e.RowIndex].Cells["IsAcceptBatch"].Value = _product.IsAcceptBatch; if (_product.IsAcceptBatch == true) { senderGrid.Rows[e.RowIndex].Cells["BatchNumber"].ReadOnly = false; senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].ReadOnly = false; } else { senderGrid.Rows[e.RowIndex].Cells["BatchNumber"].ReadOnly = true; senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].ReadOnly = true; } senderGrid.Rows[e.RowIndex].Cells["UnitPrice"].Value = vSALSalesOrder.FinalPrice; } if (e.RowIndex != -1 && e.ColumnIndex == senderGrid.Columns["ExpiryDate"].Index) { if (Convert.ToInt32(senderGrid.Rows[e.RowIndex].Cells["ProductName"].Value) == -1) { MessageBox.Show("أختر صنف أولا"); return; } DateTime result; if (!DateTime.TryParse(senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].Value.ToString(), out result)) { MessageBox.Show("صيغة تاريخ الصلاحية غير صحيحة لابد ان تكون (يوم -شهر -سنة)"); senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].Style.BackColor = Color.Red; senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].Value = ""; } else { senderGrid.Rows[e.RowIndex].Cells["ExpiryDate"].Style.BackColor = Color.White; } } } catch (Exception ex) { MessageBox.Show("حدث خطأ برجاء تكرار العمليه مره اخرى واذا تكرر الخطا برجاءالاتصال بالشخص المصمم للبرنامج وارسال رسالة الخطا التى ستظهر بعد قليل له"); MessageBox.Show(ex.Message); } }