public InterfaceOutPut Add(string data) { InterfaceOutPut output = new InterfaceOutPut(); TAB_Plan_OutRoom model = null; try { model = Newtonsoft.Json.JsonConvert.DeserializeObject <TAB_Plan_OutRoom>(data); DBRoom db = new DBRoom(); if (!db.ExistsOutRoom(model.strOutRoomGUID)) { if (db.AddOutRoom(model)) { output.result = 0; output.resultStr = "插入出寓记录成功"; } else { output.result = 1; output.resultStr = "插入出寓记录失败"; } } else { if (db.UpdateOutRoom(model)) { output.result = 0; output.resultStr = "已经存在出寓记录,更新成功"; } else { output.result = 1; output.resultStr = "已经存在出寓记录,更新失败"; } } } catch (Exception ex) { TF.CommonUtility.LogClass.logex(ex, ""); throw ex; } return(output); }
/// <summary> /// 增加一条数据OutRoom /// </summary> public bool AddOutRoom(TAB_Plan_OutRoom model) { SqlConnection conn = new SqlConnection(SqlHelper.ConnString); conn.Open(); try { using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into TAB_Plan_OutRoom("); strSql.Append("strOutRoomGUID,strTrainPlanGUID,strTrainmanGUID,dtOutRoomTime,nOutRoomVerifyID,strDutyUserGUID,strTrainmanNumber,strInRoomGUID,strSiteGUID)"); strSql.Append(" values ("); strSql.Append("@strOutRoomGUID,@strTrainPlanGUID,@strTrainmanGUID,@dtOutRoomTime,@nOutRoomVerifyID,@strDutyUserGUID,@strTrainmanNumber,@strInRoomGUID,@strSiteGUID)"); SqlParameter[] parameters = { new SqlParameter("@strOutRoomGUID", SqlDbType.VarChar, 50), new SqlParameter("@strTrainPlanGUID", SqlDbType.VarChar, 50), new SqlParameter("@strTrainmanGUID", SqlDbType.VarChar, 50), new SqlParameter("@dtOutRoomTime", SqlDbType.DateTime), new SqlParameter("@nOutRoomVerifyID", SqlDbType.Int, 4), new SqlParameter("@strDutyUserGUID", SqlDbType.VarChar, 50), new SqlParameter("@strTrainmanNumber", SqlDbType.VarChar, 50), new SqlParameter("@dtCreateTime", SqlDbType.DateTime), new SqlParameter("@strInRoomGUID", SqlDbType.VarChar, 50), new SqlParameter("@strSiteGUID", SqlDbType.VarChar, 50) }; parameters[0].Value = model.strOutRoomGUID; parameters[1].Value = model.strTrainPlanGUID; parameters[2].Value = model.strTrainmanGUID; parameters[3].Value = model.dtOutRoomTime; parameters[4].Value = model.nOutRoomVerifyID; parameters[5].Value = model.strDutyUserGUID; parameters[6].Value = model.strTrainmanNumber; parameters[7].Value = model.dtCreateTime; parameters[8].Value = model.strInRoomGUID; parameters[9].Value = model.strSiteGUID; int rows = (int)SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { string strSql3 = "update TAB_Org_Trainman set dtLastOutRoomTime='" + model.dtOutRoomTime + "' where strTrainmanGUID='" + model.strTrainmanGUID + "'"; int rows2 = (int)SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql3.ToString()); if (rows2 > 0) { trans.Commit(); return(true); } else { trans.Rollback(); return(false); } } else { trans.Rollback(); return(false); } } catch { trans.Rollback(); return(false); } } } finally { conn.Close(); } }