public int AddProduct(Product product) { if (product.Description == String.Empty || product.Description == null) { product.Description = product.Name; } IDBManager dbm = new DBManager(); int id = 0; try { dbm.CreateParameters(29); dbm.AddParameters(0, "@Name", product.Name); dbm.AddParameters(1, "@Description", product.Description); dbm.AddParameters(2, "@ProductNumber", product.ProductNumber); dbm.AddParameters(3, "@MakeFlag", product.MakeFlag); dbm.AddParameters(4, "@FinishedGoodsFlag", product.FinishedGoodsFlag); dbm.AddParameters(5, "@Color", product.Color); dbm.AddParameters(6, "@SafetyStockLevel", product.SafetyStockLevel); dbm.AddParameters(7, "@ReorderPoint", product.ReorderPoint); dbm.AddParameters(8, "@StandardCost", product.StandardCost); dbm.AddParameters(9, "@ListPrice", product.ListPrice); dbm.AddParameters(10, "@Size", product.Size); dbm.AddParameters(11, "@SizeUnitMeasureCode", product.SizeUnitMeasureCode); dbm.AddParameters(12, "@WeightUnitMeasureCode", product.WeightUnitMeasureCode); dbm.AddParameters(13, "@Weight", product.Weight); dbm.AddParameters(14, "@DaysToManufacture", product.DaysToManufacture); dbm.AddParameters(15, "@ProductLine", product.ProductLine); dbm.AddParameters(16, "@Class", product.Class); dbm.AddParameters(17, "@Style", product.Style); dbm.AddParameters(18, "@ProductSubcategoryID", product.ProductSubcategoryID); dbm.AddParameters(19, "@ProductModelID", product.ProductModelID); dbm.AddParameters(20, "@SellStartDate", product.SellStartDate); dbm.AddParameters(21, "@SellEndDate", product.SellEndDate); dbm.AddParameters(22, "@DiscontinuedDate", product.DiscontinuedDate); dbm.AddParameters(23, "@ModifiedDate", product.ModifiedDate); dbm.AddParameters(24, "@ProductID", product.ProductID); dbm.AddParameters(25, "@PrimaryVendorId", product.PrimaryVendorId); dbm.AddParameters(26, "@SecondaryVendorId", product.SecondaryVendorId); dbm.AddParameters(27, "@ActiveFlag", product.ActiveFlag); dbm.AddParameters(28, "@Comments", product.Comments); dbm.Parameters[24].Direction = ParameterDirection.Output; dbm.ExecuteNonQuery(CommandType.StoredProcedure, "InsertProduct"); id = Int32.Parse(dbm.Parameters[24].Value.ToString()); ProductInventory pi = new ProductInventory(); pi = product.ProductInventory; pi.ProductID = id; pi.AddProductInventory(pi); } catch (Exception ex) { log.Write(ex.Message, "AddProduct"); return(-1); } finally { dbm.Dispose(); } return(id); }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateFields() == false) { return; } if (dgInventory.Rows.Count < 1 || InventoryAdjustmentCount == 0) { return; } // int selectedRows = dgInventory.SelectedRows.Count; int selectedCount = 0; DialogResult result = MessageBox.Show("You are about to adjust the inventory for " + InventoryAdjustmentCount.ToString() + " item(s). Are you sure you want proceed.?", "MICS", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return; } int curIndex = 0; bool success = true; for (int row = 0; row < dgInventory.Rows.Count; row++) { if (dsProductInventory.Tables[0].Rows[row]["AdjustedQuantity"] == DBNull.Value) { continue; } if (selectedCount > InventoryAdjustmentCount) { break; } selectedCount++; //DataGridViewRow row = dgInventory.CurrentRow; //int curIndex = dgInventory.CurrentRow.Index; curIndex = row; //if (row == null) return; Cursor.Current = Cursors.WaitCursor; ProductInventory pi = new ProductInventory(); ProductAdjustmentHistory pah = new ProductAdjustmentHistory(); // int adjustedQuantity = Int32.Parse(txtAdjustedQuanity.Text.Trim()); // string reason = txtReason.Text.Trim(); try { int productid = Int32.Parse(dsProductInventory.Tables[0].Rows[row]["productid"].ToString()); //Int32.Parse(dgInventory.CurrentRow.Cells["productid"].Value.ToString()); int CurQuantity = 0; int NewQuantity = 0; if (dsProductInventory.Tables[0].Rows[row]["AdjustedQuantity"] != DBNull.Value) { NewQuantity = Int32.Parse(dsProductInventory.Tables[0].Rows[row]["AdjustedQuantity"].ToString()); } if (dsProductInventory.Tables[0].Rows[row]["Quantity"] != DBNull.Value) { CurQuantity = Int32.Parse(dsProductInventory.Tables[0].Rows[row]["Quantity"].ToString()); } pah.ProductID = productid; pah.AdjustedQuantity = NewQuantity - CurQuantity; if (dsProductInventory.Tables[0].Rows[row]["Reason"] != DBNull.Value) { pah.Reason = dsProductInventory.Tables[0].Rows[row]["Reason"].ToString(); } else { pah.Reason = ""; } // pah.AdjustedQuantity = adjustedQuantity; pah.ModifiedDate = DateTime.Now; pah.AddProductAdjustmentHistory(pah); pi.ProductID = productid; pi.Quantity = NewQuantity; pi.LocationID = 0; pi.ModifiedDate = DateTime.Now; pi.Shelf = ""; pi.Bin = 0; ProductInventory inv = new ProductInventory(); inv = inv.GetProductInventorys(productid); // pi.Quantity = (long) adjustedQuantity; //pi.ModifiedDate = DateTime.Now; if (inv.ProductID > 0) { pi.UpdateProductInventory(pi); } else { pi.AddProductInventory(pi); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Product Inventory", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor.Current = Cursors.Default; success = false; break; } finally { Cursor.Current = Cursors.Default; } } if (success) { MessageBox.Show("Inventory Adjusted successfully.", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Inventory Adjustment failed.", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Warning); } Search(curIndex); }