/// <summary> ///Save,保存方法,先删除,再增加 /// </summary> public void Save(IA_ST_UnAccountVouch01 model, SqlTransaction tran = null, params string[] str) { string tran_flag = "1"; SqlConnection conn = new SqlConnection(Dal.DataHelper.constr); conn.Open(); if (tran == null) { tran_flag = "0"; tran = conn.BeginTransaction(); } try { Delete(model, tran, str); Add(model, tran); //如果传入事物,提交否则外层提交 if (tran_flag == "0") { tran.Commit(); conn.Close(); } } catch (Exception e) { if (tran_flag == "0") { tran.Rollback(); conn.Close(); } throw e; } }
/// <summary> /// 增加一条数据 /// </summary> public override void Add(dynamic obj, SqlTransaction tran = null) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into IA_ST_UnAccountVouch01("); strSql.Append("IDUN,IDSUN,cVouTypeUN,cBustypeUN"); strSql.Append(") values ("); strSql.Append("@IDUN,@IDSUN,@cVouTypeUN,@cBustypeUN"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@IDUN", SqlDbType.Int, 4), new SqlParameter("@IDSUN", SqlDbType.Int, 4), new SqlParameter("@cVouTypeUN", SqlDbType.NVarChar, 10), new SqlParameter("@cBustypeUN", SqlDbType.NVarChar, 10) }; IA_ST_UnAccountVouch01 model = (IA_ST_UnAccountVouch01)obj; parameters[0].Value = SqlNull(model.IDUN); parameters[1].Value = SqlNull(model.IDSUN); parameters[2].Value = SqlNull(model.cVouTypeUN); parameters[3].Value = SqlNull(model.cBustypeUN); if (tran == null) { DataHelper.ExcuteNonQuery(strSql.ToString(), parameters, false); } else { DataHelper.ExcuteNonQuery(strSql.ToString(), tran, parameters, false); } }
//写入 未记账表01 public void IA_ST_UnAccVouchAdd01(List <RdRecords01> mylist, SqlTransaction tran) { List <IA_ST_UnAccountVouch01> ialist = new List <IA_ST_UnAccountVouch01>(); foreach (var i in mylist) { IA_ST_UnAccountVouch01 m = new IA_ST_UnAccountVouch01(); m.IDUN = i.ID; m.IDSUN = i.AutoID; m.cVouTypeUN = "01"; m.cBustypeUN = "普通采购"; ialist.Add(m); } //写入 未记账表 IA_ST_UnAccountVouch01Dal dal_ia = new IA_ST_UnAccountVouch01Dal(); foreach (var i in ialist) { dal_ia.Add(i, tran); } }