/// <summary> /// 获取一个加项包 /// </summary> /// <param name="id"></param> /// <returns></returns> public QyJxbJbxxModel GetJxbById(int id) { QyJxbJbxxModel model = new QyJxbJbxxModel(); using (IDbConnection conn = new DapperConnection().DbConnection) { string sql = "select * from qy_jxbjbxx a where id=@id"; model = conn.Query <QyJxbJbxxModel>(sql, new { id = id }).FirstOrDefault(); string sqltc = "select * from qy_jxbtc where jxbid=@id"; model.ltc = conn.Query <QyJxbTcModel>(sqltc, new { id = id }).ToList(); string sqlzhxm = "select * from qy_jxbzhxm where jxbid=@id"; model.lZhxm = conn.Query <QyJxbZhxmModel>(sqlzhxm, new { id = id }).ToList(); string zhxmbhs = ""; string zhxms = ""; string tcbhs = ""; string tcmcs = ""; foreach (QyJxbTcModel item in model.ltc) { tcbhs += item.tcbh + ","; tcmcs += item.tcmc + ","; } model.tcmcs = tcmcs.TrimEnd(','); model.tcbhs = tcbhs.TrimEnd(','); foreach (QyJxbZhxmModel item in model.lZhxm) { zhxmbhs += item.zhxmbh + ","; zhxms += item.zhxmmc + ","; } model.zhxmbhs = zhxmbhs.TrimEnd(','); model.zhxms = zhxms.TrimEnd(','); return(model); } }
/// <summary> /// 保存加项包 /// </summary> /// <param name="model"></param> /// <returns></returns> public int SaveJxb(QyJxbJbxxModel model) { int i = 0; using (IDbConnection conn = new DapperConnection().DbConnection) { List <QyJxbTcModel> litc = new List <QyJxbTcModel>(); foreach (string a in model.tcbhs.Split(',')) { XttcbModel item = new XttcbService().GetTc(model.yybh, a); litc.Add(new QyJxbTcModel() { yybh = model.yybh, tcbh = item.tcbh, tcmc = item.tcmc }); } List <QyJxbZhxmModel> lizhxm = new List <QyJxbZhxmModel>(); foreach (string a in model.zhxmbhs.Split(',')) { XtZhxmbModel item = new XtzhxmService().GetZhxm(model.yybh, a); lizhxm.Add(new QyJxbZhxmModel() { yybh = model.yybh, jg = item.zhxmjg, zhxmbh = item.zhxmbh, zhxmmc = item.zhxmmc }); } IDbTransaction transaction = conn.BeginTransaction(); if (model.id == 0) { string sql = "insert into qy_jxbjbxx(yybh,qybh,qymc,jxbmc,lrjs,syrq,sfqy,jg,xb,jsj,createtime,updatetime) values(@yybh,@qybh,@qymc,@jxbmc,@lrjs,@syrq,@sfqy,@jg,@xb,@jsj,getdate(),getdate());SELECT SCOPE_IDENTITY()"; string id = conn.ExecuteScalar(sql, model, transaction).ToString(); model.id = int.Parse(id); } else { string sql = "delete from qy_jxbzhxm where jxbid=@id;delete from qy_jxbtc where jxbid=@id; update qy_jxbjbxx set jxbmc=@jxbmc,lrjs=@lrjs,syrq=@syrq,sfqy=@sfqy,jg=@jg,xb=@xb,jsj=@jsj,updatetime=getdate() where id=@id"; conn.Execute(sql, model, transaction).ToString(); } string sqlZhxm = "insert into qy_jxbzhxm(jxbid,yybh,zhxmbh,zhxmmc,jg)values(" + model.id + ",@yybh,@zhxmbh,@zhxmmc,@jg)"; conn.Execute(sqlZhxm, lizhxm, transaction); string sqlTc = "insert into qy_jxbtc(jxbid,yybh,tcbh,tcmc)values(" + model.id + ",@yybh,@tcbh,@tcmc)"; conn.Execute(sqlTc, litc, transaction); transaction.Commit(); i = 1; } return(model.id); }