private void AssignNewColor(ProductColor item) { if (item == null) return; if (!colors.ContainsKey(item.ColorID)) return; ProductColor oldItem = colors[item.ColorID]; oldItem.ColorName = item.ColorName; oldItem.Remark = item.Remark; }
private ProductColor GetProductColorFrom(DataRow row) { if (row == null) return null; ProductColor pc = new ProductColor(); pc.ColorID = Formatter.GetStringValueFrom(row, "ColorID"); pc.ColorName = Formatter.GetStringValueFrom(row, "ColorName"); pc.Remark = Formatter.GetStringValueFrom(row, "Remark"); return pc; }
public ProductColor UpdateColor(ProductColor color) { if (color == null) return null; try { DataSet ds = SqlHelper.ExecuteDataset(sqlConn, "UpdateProductColor", new object[] { currentUser.UserID, color.ColorID, color.ColorName, color.Remark }); if (ds != null && ds.Tables != null && ds.Tables.Count > 0) { DataTable table = ds.Tables[0]; ProductColor pc = GetProductColorFrom(table.Rows[0]); if (pc != null) { if (!colors.ContainsKey(pc.ColorID)) colors[pc.ColorID] = pc; else AssignNewColor(pc); return pc; } } } catch (Exception ex) { LoggerBase.Instance.Error(ex.ToString()); } return null; }
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; } } }