private void PopulateProductSubCategories(int catID, ComboBox cmb) { ProductSubcategory sub = new ProductSubcategory(); ProductSubcategory selectNew = new ProductSubcategory(); ProductSubcategoryCollection col = new ProductSubcategoryCollection(); selectNew.ProductSubcategoryID = 0; selectNew.Name = "[Select One]"; string where = "[ProductCategoryID] = " + catID; string orderBy = "Name"; Cursor.Current = Cursors.WaitCursor; try { col = sub.GetProductSubcategoryCollection(where, orderBy); col.Insert(0, selectNew); cmb.DataSource = col; cmb.DisplayMember = "Name"; cmb.ValueMember = "ProductSubCategoryID"; } catch (Exception ex) { MessageBox.Show(ex.Message); Cursor.Current = Cursors.Default; } finally { sub = null; } Cursor.Current = Cursors.Default; }
public void LoadSubCategories(int CategoryId) { if (m_Loading) { return; } string where = "ProductCategoryId=" + CategoryId.ToString(); string order_by = "Name"; ProductSubcategory sub = new ProductSubcategory(); ProductSubcategoryCollection subCol = new ProductSubcategoryCollection(); try { m_Loading = true; subCol = sub.GetProductSubcategoryCollection(where, order_by); sub.ProductCategoryID = 0; sub.ProductSubcategoryID = 0; sub.Name = "All"; sub.ModifiedDate = DateTime.Now; subCol.Insert(0, sub); ddlSubCategory.DataSource = subCol; ddlSubCategory.DisplayMember = "Name"; ddlSubCategory.ValueMember = "ProductSubcategoryId"; m_Loading = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void ExportCategories() { SqlCompactConnection conn = new SqlCompactConnection(); try { StripStatus.Text = "Products Sub Categories.."; ProductSubcategory sub = new ProductSubcategory(); ProductCategory cat = new ProductCategory(); conn.DropProdctSubCategoryTable(); conn.CreateProdctSubCategoryTable(); ProductSubcategoryCollection subCol = sub.GetAllProductSubcategoryCollection(); conn.SynchForm = this; conn.AddProductSubCategory(subCol); StripStatus.Text = "Products Categories.."; conn.DropProdctCategoryTable(); conn.CreateProdctCategoryTable(); ProductCategoryCollection catCol = cat.GetAllProductCategoryCollection(); conn.AddProductCategory(catCol); sub = null; cat = null; subCol = null; catCol = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.CloseDatabase(); conn = null; } }
public ProductSubcategoryCollection GetAllProductSubcategoryDynamicCollection(string whereExpression, string orderBy) { IDBManager dbm = new DBManager(); ProductSubcategoryCollection cols = new ProductSubcategoryCollection(); try { dbm.CreateParameters(2); dbm.AddParameters(0, "@WhereCondition", whereExpression); dbm.AddParameters(1, "@OrderByExpression", orderBy); IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectProductSubcategoriesDynamic"); while (reader.Read()) { ProductSubcategory productSubcategory = new ProductSubcategory(); productSubcategory.ProductSubcategoryID = Int32.Parse(reader["ProductSubcategoryID"].ToString()); productSubcategory.ProductCategoryID = Int32.Parse(reader["ProductCategoryID"].ToString()); productSubcategory.Name = reader["Name"].ToString(); productSubcategory.ModifiedDate = DateTime.Parse(reader["ModifiedDate"].ToString()); cols.Add(productSubcategory); } } catch (Exception ex) { log.Write(ex.Message, "GetAllProductSubcategoryDynamicCollection"); throw (ex); } finally { dbm.Dispose(); } return(cols); }
public ProductSubcategoryCollection GetAllProductSubcategoryCollection() { IDBManager dbm = new DBManager(); ProductSubcategoryCollection cols = new ProductSubcategoryCollection(); try { IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectProductSubcategoriesAll"); while (reader.Read()) { ProductSubcategory productSubcategory = new ProductSubcategory(); productSubcategory.ProductSubcategoryID = Int32.Parse(reader["ProductSubcategoryID"].ToString()); productSubcategory.ProductCategoryID = Int32.Parse(reader["ProductCategoryID"].ToString()); productSubcategory.Name = reader["Name"].ToString(); productSubcategory.ModifiedDate = DateTime.Parse(reader["ModifiedDate"].ToString()); cols.Add(productSubcategory); } } catch (Exception ex) { log.Write(ex.Message, "GetAllProductSubcategoryCollection"); throw (ex); } finally { dbm.Dispose(); } return(cols); }
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; } }