public JsonResult AddCategory( string ctgTitle, string ctgColor) { var ctg = new Category_Model(ctgTitle, ctgColor, true, new List <Event_Model>()); Console.WriteLine(ctg.Title); calVM.userCalendar.Categories.Add(ctg); //call update to database to construct brand new category... //calVM.userCalendar.Calendar_Id = Find_Calendar(ctg.Calendar_Id); //try //{ // cal.Categories.Add(ctg); // db.Update(cal); //} //catch (NullReferenceException e) //{ // Console.WriteLine("Attempted to add a null category: " + e.Message); // throw; //} //db.SaveChanges(); //db.Add(calVM.userCalendar); //db.SaveChanges(); return(Json(calVM.userCalendar.ToJson())); }
public JsonResult EditCategory( string ctg_id, int ctg_index, string ctgTitle, string ctgColor) { //call update to database on category with particluar id and write the values... Category_Model ctg = calVM.userCalendar.Categories[ctg_index]; ctg.Color = ctgColor; ctg.Title = ctgTitle; //try //{ // db.Update(fetched_category); //} //catch (NullReferenceException e) //{ // Console.WriteLine("Null reference error when attempting to edit category: " + e.Message); // throw; //} //db.SaveChanges(); return(Json(calVM.userCalendar.ToJson())); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Category_Model model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.CATEGORY_ID != null) { strSql1.Append("CATEGORY_ID,"); strSql2.Append("" + model.CATEGORY_ID + ","); } if (model.CATEGORY_NAME != null) { strSql1.Append("CATEGORY_NAME,"); strSql2.Append("'" + model.CATEGORY_NAME + "',"); } if (model.PARENT_ID != null) { strSql1.Append("PARENT_ID,"); strSql2.Append("" + model.PARENT_ID + ","); } if (model.CATEGORY_STATUS != null) { strSql1.Append("CATEGORY_STATUS,"); strSql2.Append("" + model.CATEGORY_STATUS + ","); } if (model.CREATE_TIME != null) { strSql1.Append("CREATE_TIME,"); strSql2.Append("'" + model.CREATE_TIME + "',"); } if (model.CATEGORY_JUMP != null) { strSql1.Append("CATEGORY_JUMP,"); strSql2.Append("'" + model.CATEGORY_JUMP + "',"); } if (model.IMGPATH != null) { strSql1.Append("IMGPATH,"); strSql2.Append("'" + model.IMGPATH + "',"); } strSql.Append("insert into COM_CATEGORY("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); object obj = DbHelperSQL.GetSingle(strSql.ToString()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
public Get_Category_List GetCategoryList() { string status = "failed"; Get_Category_List list = new Get_Category_List(); try { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PortalConnectionString"].ToString())) { DataSet ds = new DataSet(); con.Open(); ds = SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "tmp_prc_getCategoryList"); foreach (DataTable dt in ds.Tables) { foreach (DataRow dr in dt.Rows) { Category_Model obj = new Category_Model(); if (!string.IsNullOrEmpty(dr["category_id"].ToString())) { obj.categoryId = Convert.ToInt32(dr["category_id"].ToString()); } else { obj.categoryId = 0; } if (!string.IsNullOrEmpty(dr["category_name"].ToString())) { obj.categoryName = dr["category_name"].ToString(); } else { obj.categoryName = ""; } if (!string.IsNullOrEmpty(dr["category_desc"].ToString())) { obj.categoryDesc = dr["category_desc"].ToString(); } else { obj.categoryDesc = ""; } list.list.Add(obj); } } } list.message = "fetched"; } catch (Exception ex) { list.message = ex.Message; } return(list); }
protected void Button1_Click(object sender, EventArgs e) { int ID = Convert.ToInt32(Request.Params["id"]); string CATEGORY_NAME = this.textname.Text; string CATEGORY_ID = this.textcateid.Text; string PARENT_ID = this.textpid.Text; string CATEGORY_JUMP = this.textjump.Text; Category_Model model = new Category_Model(); model.ID = ID; model.CATEGORY_ID = Convert.ToInt32(CATEGORY_ID); model.PARENT_ID = Convert.ToInt32(PARENT_ID); model.CATEGORY_NAME = CATEGORY_NAME; model.CATEGORY_JUMP = CATEGORY_JUMP; model.CREATE_TIME = DateTime.Now; string fileFullname = this.FileUpload2.FileName; string fileName = fileFullname.Substring(fileFullname.LastIndexOf("\\") + 1); string type = fileFullname.Substring(fileFullname.LastIndexOf(".") + 1); string picName = DateTime.Now.ToString("yyyyMMddhhssmmfff"); if (type == "bmp" || type == "jpg" || type == "jpeg" || type == "gif" || type == "JPG" || type == "JPEG" || type == "BMP" || type == "GIF" || type == "PNG" || type == "png") { FileUpload2.SaveAs(Server.MapPath("../NewsImage") + "\\" + picName + "." + type); aa = "../NewsImage/" + picName + "." + type; } if (aa == lj.Value) { model.IMGPATH = lj.Value.ToString(); } else if (fileFullname == null || fileFullname == "") { model.IMGPATH = lj.Value.ToString(); } else { model.IMGPATH = aa.ToString(); } //更改选择状态,如果添加,则此设备状态改为,已经使用 bool i = bll.Update(model); if (i) { Response.Write("<script>alert('保存成功!');window.location.href='com_category_list.aspx';</script>"); } else { Response.Write("<script>alert(保存失败!');window.location.href='com_category_list.aspx';</script>"); } }
public Get_Post_List PostGetContent(string id) { string status = "failed"; Get_Post_List list = new Get_Post_List(); try { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PortalConnectionString"].ToString())) { DataSet ds = new DataSet(); Post_Model obj = new Post_Model(); con.Open(); SqlParameter[] param = new SqlParameter[2]; param[0] = new SqlParameter("@seo_url", id); ds = SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "tmp_prc_getPostData", param); using (DataTable dt = ds.Tables[0]) { foreach (DataRow dr in dt.Rows) { //if (!string.IsNullOrEmpty(dr["post_id"].ToString())) //{ // obj.postId = Convert.ToInt32(dr["post_id"].ToString()); //} //else //{ // obj.postId = 0; //} if (!string.IsNullOrEmpty(dr["post_url"].ToString())) { obj.postUrl = dr["post_url"].ToString(); } else { obj.postUrl = ""; } if (!string.IsNullOrEmpty(dr["file_name"].ToString())) { obj.postIconImage = dr["file_name"].ToString(); } else { obj.postIconImage = ""; } if (!string.IsNullOrEmpty(dr["file_path"].ToString())) { obj.postIconImagePath = dr["file_path"].ToString(); } else { obj.postIconImagePath = ""; } //if (!string.IsNullOrEmpty(dr["post_category"].ToString())) //{ // obj.category = dr["post_category"].ToString(); //} //else //{ // obj.category = ""; //} if (!string.IsNullOrEmpty(dr["post_content"].ToString())) { obj.postContent = dr["post_content"].ToString(); } else { obj.postContent = ""; } if (!string.IsNullOrEmpty(dr["seo_url"].ToString())) { obj.seoUrl = dr["seo_url"].ToString(); } else { obj.seoUrl = ""; } if (!string.IsNullOrEmpty(dr["seo_title"].ToString())) { obj.seoTitle = dr["seo_title"].ToString(); } else { obj.seoTitle = ""; } if (!string.IsNullOrEmpty(dr["seo_description"].ToString())) { obj.seoDescription = dr["seo_description"].ToString(); } else { obj.seoDescription = ""; } if (!string.IsNullOrEmpty(dr["shortname"].ToString())) { obj.shortName = dr["shortname"].ToString(); } else { obj.shortName = ""; } //if (!string.IsNullOrEmpty(dr["categorycaption"].ToString())) //{ // obj.categoryName = dr["categorycaption"].ToString(); //} //else //{ // obj.categoryName = ""; //} if (!string.IsNullOrEmpty(dr["file_attachment_code"].ToString())) { obj.fileAttachmentCode = dr["file_attachment_code"].ToString(); } else { obj.fileAttachmentCode = ""; } list.list.Add(obj); } } using (DataTable dt = ds.Tables[1]) { foreach (DataRow dr in dt.Rows) { Category_Model model = new Category_Model(); if (!string.IsNullOrEmpty(dr["category_name"].ToString())) { model.categoryName = dr["category_name"].ToString(); } else { model.categoryName = ""; } if (!string.IsNullOrEmpty(dr["category_desc"].ToString())) { model.categoryDesc = dr["category_desc"].ToString(); } else { model.categoryDesc = ""; } if (!string.IsNullOrEmpty(dr["category_id"].ToString())) { model.categoryId = Convert.ToInt32(dr["category_id"]); } else { model.categoryId = 0; } list.categoryList.Add(model); } } } list.message = "fetched"; } catch (Exception ex) { list.message = ex.Message; } return(list); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Category_Model model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update COM_CATEGORY set "); if (model.CATEGORY_ID != null) { strSql.Append("CATEGORY_ID=" + model.CATEGORY_ID + ","); } if (model.CATEGORY_NAME != null) { strSql.Append("CATEGORY_NAME='" + model.CATEGORY_NAME + "',"); } else { strSql.Append("CATEGORY_NAME= null ,"); } if (model.PARENT_ID != null) { strSql.Append("PARENT_ID=" + model.PARENT_ID + ","); } if (model.CATEGORY_STATUS != null) { strSql.Append("CATEGORY_STATUS=" + model.CATEGORY_STATUS + ","); } else { strSql.Append("CATEGORY_STATUS= null ,"); } if (model.CREATE_TIME != null) { strSql.Append("CREATE_TIME='" + model.CREATE_TIME + "',"); } else { strSql.Append("CREATE_TIME= null ,"); } if (model.CATEGORY_JUMP != null) { strSql.Append("CATEGORY_JUMP='" + model.CATEGORY_JUMP + "',"); } else { strSql.Append("CATEGORY_JUMP= null ,"); } if (model.IMGPATH != null) { strSql.Append("IMGPATH='" + model.IMGPATH + "',"); } else { strSql.Append("IMGPATH= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where ID=" + model.ID + ""); int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Category_Model model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Category_Model model) { return(dal.Add(model)); }