/// <summary> /// Cập nhật thông tin đối tượng /// </summary> /// <param name="menu"></param> /// <param name="tran"></param> /// <returns></returns> public string Update(CatCustomerContract catcustomer, SqlTransaction tran = null) { string query = String.Format("UPDATE " + TableName + @" SET Code={0},Name={1},ManagementGroupID={2},DistrictID={3},ProvinceID={4},SaleStaffID={5},CreateDate=convert(datetime,{6},103),Address={7},DiliverAddress={8},TaxCode={9},Phone={10},Fax={11},Email={12},Contact={13},ContactPhone={14},ContactEmail={15},MaxAllowedDebt={16},Blocked={17},Description={18},OrderNum={19} WHERE ID=" + catcustomer.Id.ToString(), (catcustomer.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Code.ToString()) + "'" : "null").ToString(), (catcustomer.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Name.ToString()) + "'" : "null").ToString(), (catcustomer.Managementgroupid != null? catcustomer.Managementgroupid.ToString() : "null").ToString(), (catcustomer.Districtid != null? catcustomer.Districtid.ToString() : "null").ToString(), (catcustomer.Provinceid != null? catcustomer.Provinceid.ToString() : "null").ToString(), (catcustomer.Salestaffid != null? catcustomer.Salestaffid.ToString() : "null").ToString(), (catcustomer.Createdate != null? "'" + SQLHelper.RejectInjection(catcustomer.Createdate.ToString()) + "'" : "null").ToString(), (catcustomer.Address.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Address.ToString()) + "'" : "null").ToString(), (catcustomer.Diliveraddress.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Diliveraddress.ToString()) + "'" : "null").ToString(), (catcustomer.Taxcode.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Taxcode.ToString()) + "'" : "null").ToString(), (catcustomer.Phone.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Phone.ToString()) + "'" : "null").ToString(), (catcustomer.Fax.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Fax.ToString()) + "'" : "null").ToString(), (catcustomer.Email.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Email.ToString()) + "'" : "null").ToString(), (catcustomer.Contact.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Contact.ToString()) + "'" : "null").ToString(), (catcustomer.Contactphone.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Contactphone.ToString()) + "'" : "null").ToString(), (catcustomer.Contactemail.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Contactemail.ToString()) + "'" : "null").ToString(), (catcustomer.Maxalloweddebt.Trim() != String.Empty ? catcustomer.Maxalloweddebt.ToString() : "null").ToString(), (catcustomer.Blocked != null? "'" + SQLHelper.RejectInjection(catcustomer.Blocked.ToString()) + "'" : "null").ToString(), (catcustomer.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Description.ToString()) + "'" : "null").ToString(), (catcustomer.Ordernum.Trim() != String.Empty ? catcustomer.Ordernum.ToString() : "null").ToString()); if (tran == null) { DataProvider.ExecuteNonQuery(query); } else { DataProvider.ExecuteNonQueryWithTransaction(query, tran); } return(catcustomer.Id.ToString()); }
override public void RegistInstants(params object[] instants) { if (instants.Length > 0) { this.catcustomerContract = (CatCustomerContract)(instants[0]); } }
/// <summary> /// Insert đối tượng vào database /// </summary> /// <param name="menu"></param> /// <returns></returns> public string Insert(CatCustomerContract catcustomer, SqlTransaction tran = null) { DataTable dtResult = null; string query = string.Format(@"INSERT INTO Cat_Customer VALUES ({0},{1},{2},{3},{4},{5},convert(datetime,{6},103),{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19})", (catcustomer.Code.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Code.ToString()) + "'" : "null").ToString(), (catcustomer.Name.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Name.ToString()) + "'" : "null").ToString(), (catcustomer.Managementgroupid != null? catcustomer.Managementgroupid.ToString() : "null").ToString(), (catcustomer.Districtid != null? catcustomer.Districtid.ToString() : "null").ToString(), (catcustomer.Provinceid != null? catcustomer.Provinceid.ToString() : "null").ToString(), (catcustomer.Salestaffid != null? catcustomer.Salestaffid.ToString() : "null").ToString(), (catcustomer.Createdate != null? "'" + SQLHelper.RejectInjection(catcustomer.Createdate.ToString()) + "'" : "null").ToString(), (catcustomer.Address.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Address.ToString()) + "'" : "null").ToString(), (catcustomer.Diliveraddress.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Diliveraddress.ToString()) + "'" : "null").ToString(), (catcustomer.Taxcode.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Taxcode.ToString()) + "'" : "null").ToString(), (catcustomer.Phone.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Phone.ToString()) + "'" : "null").ToString(), (catcustomer.Fax.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Fax.ToString()) + "'" : "null").ToString(), (catcustomer.Email.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Email.ToString()) + "'" : "null").ToString(), (catcustomer.Contact.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Contact.ToString()) + "'" : "null").ToString(), (catcustomer.Contactphone.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Contactphone.ToString()) + "'" : "null").ToString(), (catcustomer.Contactemail.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Contactemail.ToString()) + "'" : "null").ToString(), (catcustomer.Maxalloweddebt.Trim() != String.Empty ? catcustomer.Maxalloweddebt.ToString() : "null").ToString(), (catcustomer.Blocked != null? "'" + SQLHelper.RejectInjection(catcustomer.Blocked.ToString()) + "'" : "null").ToString(), (catcustomer.Description.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catcustomer.Description.ToString()) + "'" : "null").ToString(), (catcustomer.Ordernum.Trim() != String.Empty ? catcustomer.Ordernum.ToString() : "null").ToString()); query += " ; select SCOPE_IDENTITY();"; if (tran == null) { dtResult = DataProvider.ExecuteQuery(query); } else { dtResult = DataProvider.ExecuteQueryWithTransaction(query, tran); } if (dtResult != null && dtResult.Rows.Count > 0) { return(dtResult.Rows[0][0].ToString()); } return(""); }
public HttpResponseMessage Save(string catcustomerJson) { string errMessage = string.Empty; try { CatCustomerContract catcustomer = JsonConvert.DeserializeObject <CatCustomerContract>(catcustomerJson); businessRule.RegistInstants(catcustomer); if (catcustomer.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(catcustomer))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(catcustomer))); } else { return(handleBRFailed(errMessage)); } } } catch (Exception e) { ExceptionHandler.Log(e); return(Request.CreateResponse <string>(HttpStatusCode.OK, "Có lỗi xảy ra trên chương trình.")); } }
public CatCustomerRule ValidateInstant(CatCustomerContract dto) { return(this); }