/// <summary> /// /// </summary> /// <param name="dal"></param> /// <param name="custContact"></param> /// <param name="editUser"></param> /// <returns></returns> public static bool Update(IDal dal, CCustContact custContact, string editUser) { int i; dal.Execute("UPDATE tCustContact SET ContactName=@ContactName,CustomerCode=@CustomerCode,Phone1=@Phone,Phone2=@Phone,Email=@Email,Remark=@Remark,EditUser=@EditUser,EditDate=GETDATE(),Enabled=@Enabled Where Id=@Id", out i, dal.CreateParameter("@ContactName", custContact.ContactName.Trim()), dal.CreateParameter("@CustomerCode", custContact.CustomerCode.Trim()), dal.CreateParameter("@Phone1", custContact.Phone1.Trim()), dal.CreateParameter("@Phone2", custContact.Phone2.Trim()), dal.CreateParameter("@Email", custContact.Email.Trim()), dal.CreateParameter("@Remark", custContact.Remark.Trim()), dal.CreateParameter("@EditUser", editUser), dal.CreateParameter("@Enabled", custContact.Enabled), dal.CreateParameter("@Id", custContact.Id)); if (i == 0) { return(false); } var dt = dal.Select("Select EditUser,EditDate From tCustContact Where Id=@Id", out i, dal.CreateParameter("@Id", custContact.Id)); if (i == 0) { return(false); } custContact.EditUser = Convert.ToString(dt.Rows[0]["EditUser"]); custContact.EditDate = Convert.ToDateTime(dt.Rows[0]["EditDate"]).ToString(ConfigurationManager.AppSettings["DateFormate"]); return(true); }
// POST api/contactapi public CCustContact Post(CCustContact value) { var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]]; if (user == null) { throw new HttpResponseException(new SiginFailureMessage()); } using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)) { bool ok; try { dal.Open(); ok = CustContactBll.Create(dal, value, string.Format("{0}-{1}", user.UserCode, user.UserName)); } catch (Exception ex) { if (ex.Message.StartsWith("违反了 UNIQUE KEY 约束")) { throw new HttpResponseException(new PrimaryRepeatedMessge()); } LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("{0}#{1}", "CustContact.Post", ex.Message), LogType = LogType.系统异常 }); throw new HttpResponseException(new SystemExceptionMessage()); } if (!ok) { LogBll.Write(dal, new CLog { LogContent = string.Format("新建客户{0}-{1}", value.ContactCode, value.ContactName), LogType = LogType.操作失败, LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName) }); throw new HttpResponseException(new DealFailureMessage()); } LogBll.Write(dal, new CLog { LogContent = string.Format("新建客户{0}-{1}", value.ContactCode, value.ContactName), LogType = LogType.操作成功, LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName) }); dal.Close(); return(value); } }
/// <summary> /// /// </summary> /// <param name="dal"></param> /// <param name="custContact"></param> /// <param name="editUser"></param> /// <returns></returns> public static bool Create(IDal dal, CCustContact custContact, string editUser) { int i; dal.Execute( "INSERT INTO tCustContact( CustomerCode ,ContactCode,ContactName ,Phone1 ,Phone2 ,Email ,Remark ,BuildDate ,BuildUser ,EditDate ,EditUser,Enabled )VALUES ( @CustomerCode ,@SerialNo,@ContactName ,@Phone1 ,@Phone2,@Email ,@Remark ,GETDATE(),@BuildUser ,GETDATE(),@EditUser,@Enabled)", out i, dal.CreateParameter("@CustomerCode", custContact.CustomerCode.Trim()), dal.CreateParameter("@ContactCode", custContact.ContactCode.Trim()), dal.CreateParameter("@ContactName", custContact.ContactName.Trim()), dal.CreateParameter("@Phone1", custContact.Phone1.Trim()), dal.CreateParameter("@Phone2", custContact.Phone2.Trim()), dal.CreateParameter("@Email", custContact.Email.Trim()), dal.CreateParameter("@Remark", custContact.Remark.Trim()), dal.CreateParameter("@BuildUser", editUser), dal.CreateParameter("@EditUser", editUser), dal.CreateParameter("@Enabled", custContact.Enabled)); if (i == 0) { return(false); } var dt = dal.Select("SELECT Id,BuildUser,BuildDate,EditUser,EditDate FROM tCustContact WHERE ContactCode=@ContactCode", out i, dal.CreateParameter("@ContactCode", custContact.ContactCode)); if (i == 0) { return(false); } custContact.Id = Convert.ToInt16(dt.Rows[0]["Id"]); custContact.BuildUser = Convert.ToString(dt.Rows[0]["BuildUser"]); custContact.EditUser = Convert.ToString(dt.Rows[0]["EditUser"]); custContact.BuildDate = Convert.ToDateTime(dt.Rows[0]["BuildDate"]).ToString(ConfigurationManager.AppSettings["DateFormate"]); custContact.EditDate = Convert.ToDateTime(dt.Rows[0]["EditDate"]).ToString(ConfigurationManager.AppSettings["DateFormate"]); return(true); }