Exemple #1
0
 /*
 public bool AddProduct(Product displayP)
 {
     SqlProduct p = new SqlProduct(displayP);
     hasError = false;
     SqlConnection con = new SqlConnection(conString);
     SqlCommand cmd = new SqlCommand("AddProduct", con);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("@ModelNumber", SqlDbType.VarChar, prodStringLen);
     cmd.Parameters["@ModelNumber"].Value = p.ModelNumber;
     cmd.Parameters.Add("@ModelName", SqlDbType.VarChar, prodStringLen);
     cmd.Parameters["@ModelName"].Value = p.ModelName;
     cmd.Parameters.Add("@UnitCost", SqlDbType.Decimal);
     cmd.Parameters["@UnitCost"].Value = p.UnitCost;
     cmd.Parameters.Add("@Description", SqlDbType.VarChar, 200);
     cmd.Parameters["@Description"].Value = p.Description;
     if (p.Description==null)  cmd.Parameters["@Description"].Value = DBNull.Value;
     cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar, prodStringLen);
     cmd.Parameters["@CategoryName"].Value = p.CategoryName;
     cmd.Parameters.Add("@ProductId", SqlDbType.Int, 4);
     cmd.Parameters["@ProductId"].Value = p.ProductId;
     cmd.Parameters["@ProductId"].Direction = ParameterDirection.Output;
     try
     {
         con.Open();
         int rows = cmd.ExecuteNonQuery();                       //create the new product in DB
         p.ProductId = (int)cmd.Parameters["@ProductId"].Value;  //set the returned ProductId in the SqlProduct object
         displayP.ProductAdded2DB(p);                            //update corresponding Product ProductId using SqlProduct
     }
     catch (SqlException ex)
     {
         errorMessage = "Add SQL error, " + ex.Message;
         hasError = true;
     }
     catch (Exception ex)
     {
         errorMessage = "ADD error, " + ex.Message;
         hasError = true;
     }
     finally
     {
         con.Close();
     }
     return !hasError;
 } //AddProduct()
  */
 public bool AddProduct(Product displayP)
 {
     hasError = false;
     try
     {
         SqlProduct p = new SqlProduct(displayP);
         LinqDataContext dc = new LinqDataContext();
         int? newProductId = 0;
         dc.AddProduct(p.CategoryName, p.ModelNumber, p.ModelName, p.UnitCost, p.Description, ref newProductId);
         p.ProductId = (int)newProductId;
         displayP.ProductAdded2DB(p);    //update corresponding Product ProductId using SqlProduct
     }
     catch (Exception ex)
     {
         errorMessage = "Add error, " + ex.Message;
         hasError = true;
     }
     return !hasError;
 }
        //check all product fields for validity
        public bool ChkProductForAdd(Product p)
        {
            int errCnt = 0;
            if (String.IsNullOrEmpty(p.ModelNumber))
            { errCnt++; ModelNumberBrush = errorBrush; }
            else ModelNumberBrush = okBrush;
            if (String.IsNullOrEmpty(p.ModelName))
            { errCnt++; ModelNameBrush = errorBrush; }
            else ModelNameBrush = okBrush;
            if (String.IsNullOrEmpty(p.CategoryName))
            { errCnt++; CategoryNameBrush = errorBrush; }
            else CategoryNameBrush = okBrush;

            if (!ChkUnitCost(p.UnitCost))
            { errCnt++; UnitCostBrush = errorBrush; }

            if (errCnt == 0) { Status = "OK"; return true; }
            else { Status = "ADD, missing or invalid fields."; return false; }
        }
 public void ProcessProduct(Product p)
 {
     if (p == null) { /*DisplayedProduct = null;*/  isSelected = false;  return; }
     Product temp = new Product();
     temp.CopyProduct(p);
     DisplayedProduct = temp;
     isSelected = true;
     stat.NoError();
 }
 private void GetProducts()
 {
     isSelected = false;
     stat.NoError();
     DisplayedProduct = new Product();
     App.Messenger.NotifyColleagues("GetProducts");
 }
 private void ClearProductDisplay()
 {
     isSelected = false;
     stat.NoError();
     DisplayedProduct = new Product();
     App.Messenger.NotifyColleagues("ProductCleared");
 }
Exemple #6
0
 /*
 private string GetStringOrNull(SqlDataReader reader, string columnName)
 {
     return reader.IsDBNull(reader.GetOrdinal(columnName)) ? "" : (string)reader[columnName];
 }
 */
 /*
 private const int prodStringLen = 50;
 public bool UpdateProduct(Product displayP)
 {
     SqlProduct p = new SqlProduct( displayP);
     hasError = false;
     SqlConnection con = new SqlConnection(conString);
     SqlCommand cmd = new SqlCommand("UpdateProduct", con);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("@ProductId", SqlDbType.Int, 4);
     cmd.Parameters["@ProductId"].Value = p.ProductId;
     cmd.Parameters.Add("@ModelNumber", SqlDbType.VarChar, prodStringLen);
     cmd.Parameters["@ModelNumber"].Value = p.ModelNumber;
     cmd.Parameters.Add("@ModelName", SqlDbType.VarChar, prodStringLen);
     cmd.Parameters["@ModelName"].Value = p.ModelName;
     cmd.Parameters.Add("@UnitCost", SqlDbType.Decimal);
     cmd.Parameters["@UnitCost"].Value = p.UnitCost;
     cmd.Parameters.Add("@Description", SqlDbType.VarChar, 200);
     cmd.Parameters["@Description"].Value = p.Description;
     cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar, prodStringLen);
     cmd.Parameters["@CategoryName"].Value = p.CategoryName;
     int rows = 0;
     try
     {
         con.Open();
         rows = cmd.ExecuteNonQuery();
     }
     catch (SqlException ex)
     {
         errorMessage = "Update SQL error, " + ex.Message;
         hasError = true;
     }
     catch (Exception ex)
     {
         errorMessage = "Update error, " + ex.Message;
         hasError = true;
     }
     finally
     {
         con.Close();
     }
     return (!hasError);
 } //UpdateProduct()
 */
 public bool UpdateProduct(Product displayP)
 {
     try
     {
         SqlProduct p = new SqlProduct(displayP);
         LinqDataContext dc = new LinqDataContext();
         dc.UpdateProduct(p.ProductId, p.CategoryName, p.ModelNumber, p.ModelName, p.UnitCost, p.Description);
     }
     catch (Exception ex)
     {
         errorMessage = "Update error, " + ex.Message;
         hasError = true;
     }
     return (!hasError);
 }
Exemple #7
0
 public void CopyProduct(Product p)
 {
     this._productId = p._ProductId;
     this.ModelNumber = p.ModelNumber;
     this.ModelName = p.ModelName;
     this.UnitCost = p.UnitCost;
     this.CategoryName = p.CategoryName;
     this.Description = p.Description;
 }
Exemple #8
0
 public SqlProduct(Product p)
 {
     ProductId = p._ProductId;
     ModelNumber = p.ModelNumber;
     ModelName = p.ModelName;
     UnitCost = Convert.ToDecimal(p.UnitCost);
     Description = p.Description;
     CategoryName = p.CategoryName;
 }