private int AddCategory() { int ret = 0; Cursor.Current = Cursors.WaitCursor; string strCategory = txtCategory.Text.Trim(); ProductCategory pc = new ProductCategory(); try { pc.Name = strCategory; int pcid = pc.Exists(pc.Name); if (pcid > 0) { DialogResult result = MessageBox.Show("Procut Category " + pc.Name + " already exists\nWould you like to update it?", "MICS", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { pc.UpdateProductCategory(pc); MessageBox.Show("Record updated successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Record is not saved", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { pc.AddProductCategory(pc); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Product Categories", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor.Current = Cursors.Default; } Cursor.Current = Cursors.Default; return(ret); }
public HttpResponseMessage Create(HttpRequestMessage request, ProductCategoryModel model) { return(CreateHttpRes(request, () => { HttpResponseMessage res = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { ProductCategory productCategory = new ProductCategory(); productCategory.CreatedBy = User.Identity.Name; productCategory.AddProductCategory(model); var result = _productCategoryService.Add(productCategory); _productCategoryService.SaveChange(); res = request.CreateResponse(HttpStatusCode.Created, result); } return res; })); }
private void SaveProducts() { Cursor.Current = Cursors.WaitCursor; try { int catid = 0; int subcatid = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { ProductCategory cat = new ProductCategory(); ProductCategoryCollection catCol = new ProductCategoryCollection(); ProductSubcategory sub = new ProductSubcategory(); ProductSubcategoryCollection subCol = new ProductSubcategoryCollection(); Product prod = new Product(); string where = String.Empty; string orderBy = String.Empty; cat.Name = dataGridView1.Rows[i].Cells["category"].Value.ToString(); cat.ModifiedDate = DateTime.Now; if (cat.Name == "Candy") { MessageBox.Show("here"); } if (!cat.Exsists(cat.Name)) { catid = cat.AddProductCategory(cat); } else { where = "[Name]='" + cat.Name + "'"; catCol = cat.GetProductCategoryCollection(where, orderBy); if (catCol.Count > 0) { catid = catCol[0].ProductCategoryID; } else { MessageBox.Show("error"); log.Write(cat.Name, "Loading Products"); } } sub.ProductCategoryID = catid; sub.Name = dataGridView1.Rows[i].Cells["subcategory"].Value.ToString(); sub.ModifiedDate = DateTime.Now; if (sub.Name == "Pacifire") { MessageBox.Show("Stealers"); } if (sub.Exsists(sub.Name)) { where = "[Name]='" + sub.Name + "'"; subCol = sub.GetProductSubcategoryCollection(where, orderBy); if (subCol.Count > 0) { subcatid = subCol[0].ProductSubcategoryID; } } else { subcatid = sub.AddProductSubcategory(sub); } prod.ProductSubcategoryID = subcatid; prod.Name = dataGridView1.Rows[i].Cells["productname"].Value.ToString(); prod.Class = String.Empty; prod.Color = String.Empty; prod.DaysToManufacture = 0; prod.Description = dataGridView1.Rows[i].Cells["productname"].Value.ToString(); prod.DiscontinuedDate = DateTime.Parse("01/01/1900"); prod.FinishedGoodsFlag = true; prod.ListPrice = dataGridView1.Rows[i].Cells["price"].Value.ToString() == String.Empty?0.00m:Decimal.Parse(dataGridView1.Rows[i].Cells["price"].Value.ToString()); prod.MakeFlag = true; prod.ModifiedDate = DateTime.Now; prod.ProductLine = String.Empty; prod.ProductModelID = 0; prod.ProductNumber = String.Empty; prod.ReorderPoint = 0;// Int16.Parse(dataGridView1.Rows[i].Cells["Reorder Point"].Value.ToString()); prod.SafetyStockLevel = 0; prod.SellEndDate = DateTime.Now; prod.SellStartDate = DateTime.Now; prod.Size = String.Empty; prod.SizeUnitMeasureCode = String.Empty; prod.StandardCost = Decimal.Parse(dataGridView1.Rows[i].Cells["cost"].Value.ToString()); prod.Style = String.Empty; prod.Weight = 0.00m; prod.WeightUnitMeasureCode = String.Empty; prod.AddProduct(prod); cat = null; sub = null; prod = null; } } catch (Exception ex) { MessageBox.Show(ex.Message); Cursor.Current = Cursors.Default; } finally { MessageBox.Show("Done"); Cursor.Current = Cursors.Default; } }