public ProductSubCategory UpdateSubCategory(ProductSubCategory subCategory) { if (subCategory == null) return null; try { DataSet ds = SqlHelper.ExecuteDataset(sqlConn, "UpdateProductSubCategory", new object[] { currentUser.UserID, subCategory.CategoryID, subCategory.SubCategoryID, subCategory.SubCategoryName, subCategory.Remark }); if (ds != null && ds.Tables != null && ds.Tables.Count > 0) { DataTable table = ds.Tables[0]; ProductSubCategory psc = GetProductSubCategoryFrom(table.Rows[0]); if (psc != null) { if (!subCategories.ContainsKey(psc.CategoryID)) subCategories[psc.CategoryID] = psc; else AssignNewSubCategory(psc); return psc; } } } catch (Exception ex) { LoggerBase.Instance.Error(ex.ToString()); } return null; }
private void AssignNewSubCategory(ProductSubCategory item) { if (item == null) return; if (!subCategories.ContainsKey(item.SubCategoryID)) return; ProductSubCategory oldItem = subCategories[item.SubCategoryID]; oldItem.SubCategoryName = item.SubCategoryName; oldItem.Remark = item.Remark; }
private ProductSubCategory GetProductSubCategoryFrom(DataRow row) { if (row == null) return null; ProductSubCategory psc = new ProductSubCategory(); psc.CategoryID = Formatter.GetStringValueFrom(row, "CategoryID"); psc.Remark = Formatter.GetStringValueFrom(row, "Remark"); psc.SubCategoryID = Formatter.GetStringValueFrom(row, "SubCategoryID"); psc.SubCategoryName = Formatter.GetStringValueFrom(row, "SubCategoryName"); return psc; }
private void btn_New_Click(object sender, EventArgs e) { NewParameter form = new NewParameter(); if (form.ShowDialog(this) == DialogResult.OK) { bool ok = false; int i = cbx_ParamName.SelectedIndex; string paramName = form.ParameterName; string paramRemark = form.ParameterRemark; switch (cbx_ParamType.SelectedIndex) { case 0: //Category ProductCategory category = new ProductCategory(); category.CategoryName = paramName; category.Remark = paramRemark; ok = (DataService.Instance.CreateCategory(category) != null); if (ok) { cbx_ParamName.Items.Clear(); cbx_ParamName.Items.AddRange(DataService.Instance.Categories.ToArray()); } break; case 1: //Sub Category ProductSubCategory subCategory = cbx_ParamName.SelectedItem as ProductSubCategory; if (subCategory != null) { ProductSubCategory newSubCate = new ProductSubCategory(); newSubCate.CategoryID = subCategory.CategoryID; newSubCate.Remark = paramRemark; newSubCate.SubCategoryName = paramName; ok = (DataService.Instance.CreateSubCategory(newSubCate) != null); if (ok) { cbx_ParamName.Items.Clear(); cbx_ParamName.Items.AddRange(DataService.Instance.SubCategories.ToArray()); } } break; case 2: //Color ProductColor color = new ProductColor(); color.ColorName = paramName; color.Remark = paramRemark; ok = (DataService.Instance.CreateColor(color) != null); if (ok) { cbx_ParamName.Items.Clear(); cbx_ParamName.Items.AddRange(DataService.Instance.Colors.ToArray()); } break; case 3: //Crafts ProductCrafts crafts = new ProductCrafts(); crafts.CraftsName = paramName; crafts.Remark = paramRemark; ok = (DataService.Instance.CreateCrafts(crafts) != null); if (ok) { cbx_ParamName.Items.Clear(); cbx_ParamName.Items.AddRange(DataService.Instance.Crafts.ToArray()); } break; case 4: //Material ProductMaterial material = new ProductMaterial(); material.MaterialName = paramName; material.Remark = paramRemark; ok = (DataService.Instance.CreateMaterial(material) != null); if (ok) { cbx_ParamName.Items.Clear(); cbx_ParamName.Items.AddRange(DataService.Instance.Materials.ToArray()); } break; default: break; } if (!ok) { MessageBox.Show(ResourceHelper.Instance.GetString("NewParameter.New.Failed"), Text); } else { if (cbx_ParamName.Items.Count > i) cbx_ParamName.SelectedIndex = i; } } }