public void NewInventory_Add() { // SETUP InventoryObject io = new InventoryObject(); io.Consignor = 5; io.Description = "Test Inventory Object"; io.Price = 123.45M; io.Comment = "Comment"; // TRIGGER MockInventoryUtilities t = new MockInventoryUtilities(); bool actualResult = t.SaveInventory(io); // VALIDATE Assert.IsTrue(actualResult); }
/// <summary> /// Save inventory to the database /// </summary> /// <returns></returns> private bool SaveInventory() { for (int iRowCount = 0; iRowCount < dgInventory.Rows.Count-1; iRowCount++) { InventoryClasses.InventoryObject newInventory = new InventoryClasses.InventoryObject(); newInventory.Consignor = int.Parse(txtConsignerID.Text.ToString()); newInventory.Description = dgInventory[0, iRowCount].Value.ToString(); newInventory.Price = decimal.Parse(dgInventory[1, iRowCount].Value.ToString()); string comment = string.Empty; if (dgInventory[2, iRowCount].Value != null) { comment = dgInventory[2, iRowCount].Value.ToString(); } newInventory.Comment = comment; InventoryClasses.InventoryUtilities iu = new InventoryClasses.InventoryUtilities(); int returnValue = iu.SaveInventory(newInventory); if (returnValue == -1) { return false; } } return true; }
/// <summary> /// save the inventory item /// </summary> /// <returns></returns> private bool SaveInventoryItem() { InventoryClasses.InventoryObject io = new InventoryClasses.InventoryObject(); InventoryClasses.InventoryUtilities iu = new InventoryClasses.InventoryUtilities(); io.ItemID = txtItemID.Text; io.Description = txtDescription.Text; decimal dpResult = 0; if (decimal.TryParse(txtAskPrice.Text, out dpResult)) { io.Price = dpResult; } else { io.Price = dpResult; } decimal dsResult = 0; if (decimal.TryParse(txtSellPrice.Text, out dsResult)) { io.SellPrice = dsResult; } else { io.SellPrice = dsResult; } io.Comment = txtComment.Text; io.SoldStatus = cboSoldStatus.SelectedIndex; io.Returnable = ckReturn.Checked; //CHECK FOR NULL DATES DateTime dtResult = DateTime.MinValue; if (DateTime.TryParse(txtDateIn.Text, out dtResult)) { io.DateIn = dtResult; } else { io.DateIn = DateTime.MinValue; } if (DateTime.TryParse(txtDateSold.Text, out dtResult)) { io.DateSold = dtResult; } else { io.DateSold = DateTime.MinValue; } if (DateTime.TryParse(txtDatePaid.Text, out dtResult)) { io.DatePaid = dtResult; } else { io.DatePaid = DateTime.MinValue; } decimal pResult = 0; if (decimal.TryParse(txtPaidAmount.Text, out pResult)) { io.PaidAmount = pResult; } else { io.PaidAmount = pResult; } bool returnValue = iu.UpdateInventory(io); return returnValue; }
/// <summary> /// load up the found details for an inventory item /// </summary> /// <param name="ItemID"></param> private void LoadDetails(int ItemID) { try { InventoryClasses.InventoryUtilities iu = new InventoryClasses.InventoryUtilities(); InventoryClasses.InventoryObject io = new InventoryClasses.InventoryObject(); io = iu.GetInventoryDetails(ItemID.ToString()); if (io == null) { MessageBox.Show("There was a problem retrieving that inventory item", Properties.Settings.Default.MessageBoxTitle, MessageBoxButtons.OK); } else { txtItemID.Text = io.ItemID; txtDescription.Text = io.Description; txtAskPrice.Text = decimal.Round(io.Price, 2).ToString(); txtDateIn.Text = io.DateIn.ToString(); txtSellPrice.Text = decimal.Round(io.SellPrice, 2).ToString(); if (DateTime.Compare(io.DateSold, DateTime.MinValue) == 0) { txtDateSold.Text = string.Empty; } else { txtDateSold.Text = io.DateSold.ToString(); } if (DateTime.Compare(io.DatePaid, DateTime.MinValue) == 0) { txtDatePaid.Text = string.Empty; } else { txtDatePaid.Text = io.DatePaid.ToString(); } txtPaidAmount.Text = decimal.Round(io.PaidAmount, 2).ToString(); txtComment.Text = io.Comment; cboSoldStatus.SelectedIndex = io.SoldStatus; this.ckReturn.Checked = io.Returnable; txtConsignID.Text = io.Consignor.ToString(); txtConsignor.Text = io.ConsignorName; if (io.Donate) { lblDonateCheck.Text = "x"; } else { lblDonateCheck.Text = "o"; } } } catch (Exception e) { MessageBox.Show(string.Format("There was an error: {0}", e.Message), Properties.Settings.Default.MessageBoxTitle, MessageBoxButtons.OK); } }
public InventoryObject GetInventoryDetails(string itemID) { InventoryObject returnItem = new InventoryObject(); var d = new Decode(); SqlConnection cn = new SqlConnection(d.ConnectionString); SqlCommand cmd = new SqlCommand("DTUSER.ItemID_Select"); SqlDataReader dr; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@pItemID", SqlDbType.Int).Value = itemID; try { cn.Open(); cmd.Connection = cn; dr = cmd.ExecuteReader(); while (dr.Read()) { var foundInventory = new InventoryObject(); foundInventory.ItemID = dr.GetValue(0).ToString(); foundInventory.Description = dr.GetValue(1).ToString(); foundInventory.Price = dr.GetSqlMoney(2).Value; foundInventory.DateIn = dr.GetSqlDateTime(3).Value; //HAVE TO CHECK FOR NULL VALUES ON SOLD RANGE if (dr.IsDBNull(4) == true) { foundInventory.SellPrice = 0; } else { foundInventory.SellPrice = dr.GetSqlMoney(4).Value; } if (dr.IsDBNull(5) == true) { foundInventory.DateSold = DateTime.MinValue; } else { foundInventory.DateSold = dr.GetSqlDateTime(5).Value; } if (dr.IsDBNull(6) == true) { foundInventory.DatePaid = DateTime.MinValue; } else { foundInventory.DatePaid = dr.GetSqlDateTime(6).Value; } if (dr.IsDBNull(7) == true) { foundInventory.PaidAmount = 0; } else { foundInventory.PaidAmount = dr.GetSqlMoney(7).Value; } foundInventory.Comment = dr.GetValue(8).ToString(); foundInventory.SoldStatus = dr.GetInt32(9); foundInventory.Returnable = dr.GetBoolean(10); foundInventory.Consignor = dr.GetSqlInt32(11).Value; foundInventory.ConsignorName = dr.GetValue(13) + ", " + dr.GetValue(12); foundInventory.Donate = dr.GetBoolean(14); returnItem = foundInventory; } dr.Close(); } catch (Exception) { throw; } finally { if ( cn.State != ConnectionState.Closed) { cn.Close(); } } return returnItem; }
/// <summary> /// updates a given inventory object /// </summary> /// <param name="io"></param> /// <returns></returns> public bool UpdateInventory(InventoryObject io) { var d = new Decode(); SqlConnection cn = new SqlConnection(d.ConnectionString); SqlCommand cmd = new SqlCommand("DTUSER.Inventory_Update"); cmd.CommandType = CommandType.StoredProcedure; SqlParameter returnValue = new SqlParameter("@Return_Value", DbType.Int32); returnValue.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(returnValue); try { cn.Open(); cmd.Connection = cn; cmd.Parameters.Add("@pItemNumber", SqlDbType.Int).Value = io.ItemID; cmd.Parameters.Add("@pItemDescription", SqlDbType.NVarChar).Value = io.Description; cmd.Parameters.Add("@pAskingPrice", SqlDbType.Decimal).Value = io.Price; cmd.Parameters.Add("@pSellingPrice", SqlDbType.Decimal).Value = io.SellPrice; cmd.Parameters.Add("@pComment", SqlDbType.NVarChar).Value = io.Comment; cmd.Parameters.Add("@pSoldStatus", SqlDbType.Int).Value = io.SoldStatus; cmd.Parameters.Add("@pReturned", SqlDbType.Bit).Value = io.Returnable; cmd.Parameters.Add("@pDateIn", SqlDbType.DateTime).Value = io.DateIn; if (DateTime.Compare(io.DateSold, DateTime.MinValue) == 0) { cmd.Parameters.Add("@pDateSold", SqlDbType.DateTime).Value = DBNull.Value; } else { cmd.Parameters.Add("@pDateSold", SqlDbType.DateTime).Value = io.DateSold; } if (DateTime.Compare(io.DatePaid, DateTime.MinValue) == 0) { cmd.Parameters.Add("@pDatePaid", SqlDbType.DateTime).Value = DBNull.Value; } else { cmd.Parameters.Add("@pDatePaid", SqlDbType.DateTime).Value = io.DatePaid; } cmd.Parameters.Add("@pAmountPaid", SqlDbType.Money).Value = io.PaidAmount; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { if (cn.State != ConnectionState.Closed) { cn.Close(); } } return true; }
public int SaveInventory(InventoryObject newInventory) { int newInventoryID = 0; var d = new Decode(); SqlConnection cn = new SqlConnection(d.ConnectionString); SqlCommand cmd = new SqlCommand("DTUSER.Inventory_Insert"); SqlParameter returnValue = new SqlParameter("@Return_Value", DbType.Int32); returnValue.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(returnValue); cmd.CommandType = CommandType.StoredProcedure; try { cn.Open(); cmd.Connection = cn; cmd.Parameters.Add("@pConsignorID", SqlDbType.Int).Value = newInventory.Consignor; cmd.Parameters.Add("@pItemDescription", SqlDbType.NVarChar).Value = newInventory.Description; cmd.Parameters.Add("@pAskingPrice", SqlDbType.Decimal).Value = newInventory.Price; if (string.IsNullOrEmpty(newInventory.Comment)) { cmd.Parameters.Add("@pComment", SqlDbType.NVarChar).Value = DBNull.Value; } else { cmd.Parameters.Add("@pComment", SqlDbType.NVarChar).Value = newInventory.Comment; } cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); newInventoryID = (int)returnValue.Value; } catch (Exception) { newInventoryID = -1; } finally { if (cn.State != ConnectionState.Closed) { cn.Close(); } } return newInventoryID; }