コード例 #1
0
 private FoodCategory ToCategory(DataRow row)
 {
     FoodCategory category = new FoodCategory();
     category.id = (int)row["id"];
     category.categoryName = (string)row["categoryName"];
     category.categoryBelong = (string)row["categoryBelong"];
     return category;
 }
コード例 #2
0
 public void AddCategory(FoodCategory category)
 {
     try
     {
         string sql = "INSERT INTO `FoodCategory`(`categoryName`,`categoryBelong`)VALUES (@categoryName,@categoryBelong)";
         DbUtil.ExecuteNonQuery(sql, new MySqlParameter("@categoryName", category.categoryName),
             new MySqlParameter("@categoryBelong", category.categoryBelong));
     }
     catch (Exception ex)
     {
         throw new Exception("添加分类失败" + ex.Message);
     }
 }
コード例 #3
0
ファイル: FormAddCategory.cs プロジェクト: JimDeng/WenJiaPC
 private void lbAddCategory_Click(object sender, EventArgs e)
 {
     string categoryName = tbCategoryName.Text.Trim();
     if (categoryName == "")
     {
         MessageBox.Show("分类名称不能为空!");
     }
     else
     {
         FoodCategory category = new FoodCategory();
         category.categoryName = categoryName;
         category.categoryBelong = cbCategoryBelong.Text.Trim();
         FoodCategoryService service = new FoodCategoryService();
         service.AddCategory(category);
         this.DialogResult = System.Windows.Forms.DialogResult.OK;
     }
 }