/// <summary> /// 增加一条数据,及其子表数据 /// </summary> public int Add(Model.article_news model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dt_article("); strSql.Append("channel_id,category_id,title,link_url,img_url,seo_title,seo_keywords,seo_description,content,sort_id,click,is_lock,user_id,add_time)"); strSql.Append(" values ("); strSql.Append("@channel_id,@category_id,@title,@link_url,@img_url,@seo_title,@seo_keywords,@seo_description,@content,@sort_id,@click,@is_lock,@user_id,@add_time)"); strSql.Append(";set @ReturnValue= @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@category_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@link_url", SqlDbType.NVarChar, 255), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@seo_title", SqlDbType.NVarChar, 255), new SqlParameter("@seo_keywords", SqlDbType.NVarChar, 255), new SqlParameter("@seo_description", SqlDbType.NVarChar, 255), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@click", SqlDbType.Int, 4), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@ReturnValue", SqlDbType.Int) }; parameters[0].Value = model.channel_id; parameters[1].Value = model.category_id; parameters[2].Value = model.title; parameters[3].Value = model.link_url; parameters[4].Value = model.img_url; parameters[5].Value = model.seo_title; parameters[6].Value = model.seo_keywords; parameters[7].Value = model.seo_description; parameters[8].Value = model.content; parameters[9].Value = model.sort_id; parameters[10].Value = model.click; parameters[11].Value = model.is_lock; parameters[12].Value = model.user_id; parameters[13].Value = model.add_time; parameters[14].Direction = ParameterDirection.Output; List <CommandInfo> sqllist = new List <CommandInfo>(); CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters); sqllist.Add(cmd); //副表信息 StringBuilder strSql2 = new StringBuilder(); strSql2.Append("insert into dt_article_news("); strSql2.Append("id,author,[from],zhaiyao,is_msg,is_top,is_red,is_hot,is_slide)"); strSql2.Append(" values ("); strSql2.Append("@id,@author,@from,@zhaiyao,@is_msg,@is_top,@is_red,@is_hot,@is_slide)"); SqlParameter[] parameters2 = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@author", SqlDbType.NVarChar, 100), new SqlParameter("@from", SqlDbType.NVarChar, 50), new SqlParameter("@zhaiyao", SqlDbType.NVarChar, 255), new SqlParameter("@is_msg", SqlDbType.TinyInt, 1), new SqlParameter("@is_top", SqlDbType.TinyInt, 1), new SqlParameter("@is_red", SqlDbType.TinyInt, 1), new SqlParameter("@is_hot", SqlDbType.TinyInt, 1), new SqlParameter("@is_slide", SqlDbType.TinyInt, 1) }; parameters2[0].Direction = ParameterDirection.InputOutput; parameters2[1].Value = model.author; parameters2[2].Value = model.from; parameters2[3].Value = model.zhaiyao; parameters2[4].Value = model.is_msg; parameters2[5].Value = model.is_top; parameters2[6].Value = model.is_red; parameters2[7].Value = model.is_hot; parameters2[8].Value = model.is_slide; cmd = new CommandInfo(strSql2.ToString(), parameters2); sqllist.Add(cmd); ////顶和踩 //StringBuilder strSql3 = new StringBuilder(); //strSql3.Append("insert into dt_article_diggs("); //strSql3.Append("id,digg_good,digg_bad)"); //strSql3.Append(" values ("); //strSql3.Append("@id,@digg_good,@digg_bad)"); //SqlParameter[] parameters3 = { // new SqlParameter("@id", SqlDbType.Int,4), // new SqlParameter("@digg_good", SqlDbType.Int,4), // new SqlParameter("@digg_bad", SqlDbType.Int,4)}; //parameters3[0].Direction = ParameterDirection.InputOutput; //parameters3[1].Value = model.digg_good; //parameters3[2].Value = model.digg_bad; //cmd = new CommandInfo(strSql3.ToString(), parameters3); //sqllist.Add(cmd); //图片相册 if (model.albums != null) { StringBuilder strSql4; foreach (Model.article_albums models in model.albums) { strSql4 = new StringBuilder(); strSql4.Append("insert into dt_article_albums("); strSql4.Append("article_id,big_img,small_img,remark)"); strSql4.Append(" values ("); strSql4.Append("@article_id,@big_img,@small_img,@remark)"); SqlParameter[] parameters4 = { new SqlParameter("@article_id", SqlDbType.Int, 4), new SqlParameter("@big_img", SqlDbType.NVarChar, 255), new SqlParameter("@small_img", SqlDbType.NVarChar, 255), new SqlParameter("@remark", SqlDbType.NVarChar, 500) }; parameters4[0].Direction = ParameterDirection.InputOutput; parameters4[1].Value = models.big_img; parameters4[2].Value = models.small_img; parameters4[3].Value = models.remark; cmd = new CommandInfo(strSql4.ToString(), parameters4); sqllist.Add(cmd); } } ////扩展属性 //if (model.attribute_values != null) //{ // StringBuilder strSql5; // foreach (Model.attribute_value models in model.attribute_values) // { // strSql5 = new StringBuilder(); // strSql5.Append("insert into dt_attribute_value("); // strSql5.Append("article_id,attribute_id,title,content)"); // strSql5.Append(" values ("); // strSql5.Append("@article_id,@attribute_id,@title,@content)"); // SqlParameter[] parameters5 = { // new SqlParameter("@article_id", SqlDbType.Int,4), // new SqlParameter("@attribute_id", SqlDbType.Int,4), // new SqlParameter("@title", SqlDbType.NVarChar,100), // new SqlParameter("@content", SqlDbType.NText)}; // parameters5[0].Direction = ParameterDirection.InputOutput; // parameters5[1].Value = models.attribute_id; // parameters5[2].Value = models.title; // parameters5[3].Value = models.content; // cmd = new CommandInfo(strSql5.ToString(), parameters5); // sqllist.Add(cmd); // } //} DbHelperSQL2.ExecuteSqlTranWithIndentity(sqllist); return((int)parameters[14].Value); }