示例#1
0
        /// <summary>
        /// Cap nhat thong tin khach hang
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public int UpdateCustomer(CustomerEntity p)
        {
            try
            {
                LogClass.SaveDBLog("UpdateCustomer: " + JsonConvert.SerializeObject(p));
                using (SqlConnection connection = new SqlConnection(connectString))
                {
                    connection.Open();
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandTimeout = Constants.TIMOUT_CONNECT_SQL;
                        cmd.Connection     = connection;
                        cmd.CommandType    = CommandType.StoredProcedure;
                        cmd.CommandText    = "sp_Api_UpdateCustomer";
                        cmd.Parameters.Add("@CustomerID", SqlDbType.Int);
                        cmd.Parameters["@CustomerID"].Value = p.CustomertID;
                        cmd.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 250);
                        cmd.Parameters["@CompanyName"].Value = p.CompanyName;
                        cmd.Parameters.Add("@TaxCode", SqlDbType.VarChar, 15);
                        cmd.Parameters["@TaxCode"].Value = p.TaxCode;

                        cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 150);
                        cmd.Parameters["@Address"].Value = p.Address;
                        cmd.Parameters.Add("@City", SqlDbType.SmallInt);
                        cmd.Parameters["@City"].Value = p.City;
                        cmd.Parameters.Add("@Country", SqlDbType.SmallInt);
                        cmd.Parameters["@Country"].Value = p.Country;
                        cmd.Parameters.Add("@Address1", SqlDbType.NVarChar, 150);
                        cmd.Parameters["@Address1"].Value = p.Address1;
                        cmd.Parameters.Add("@City1", SqlDbType.SmallInt);
                        cmd.Parameters["@City1"].Value = p.City1;
                        cmd.Parameters.Add("@Country1", SqlDbType.SmallInt);
                        cmd.Parameters["@Country1"].Value = p.Country1;
                        cmd.Parameters.Add("@Address2", SqlDbType.NVarChar, 150);
                        cmd.Parameters["@Address2"].Value = p.Address2;
                        cmd.Parameters.Add("@City2", SqlDbType.SmallInt);
                        cmd.Parameters["@City2"].Value = p.City2;
                        cmd.Parameters.Add("@Country2", SqlDbType.SmallInt);
                        cmd.Parameters["@Country2"].Value = p.Country2;

                        cmd.Parameters.Add("@Email", SqlDbType.VarChar, 80);
                        cmd.Parameters["@Email"].Value = p.Email;
                        cmd.Parameters.Add("@Phone", SqlDbType.VarChar, 50);
                        cmd.Parameters["@Phone"].Value = p.Phone;
                        cmd.Parameters.Add("@Contact", SqlDbType.NVarChar, 250);
                        cmd.Parameters["@Contact"].Value = p.Contact;
                        cmd.Parameters.Add("@Status", SqlDbType.TinyInt);
                        cmd.Parameters["@Status"].Value = p.Status;
                        cmd.Parameters.Add("@UserEdit", SqlDbType.Int);
                        cmd.Parameters["@UserEdit"].Value = p.UserID;
                        cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 50);
                        cmd.Parameters["@UserName"].Value = p.UserName;
                        cmd.Parameters.Add("@KM", SqlDbType.SmallInt);
                        cmd.Parameters["@KM"].Value = p.KM;
                        cmd.Parameters.Add("@KM1", SqlDbType.SmallInt);
                        cmd.Parameters["@KM1"].Value = p.KM1;
                        cmd.Parameters.Add("@KM2", SqlDbType.SmallInt);
                        cmd.Parameters["@KM2"].Value = p.KM2;
                        cmd.Parameters.Add("@LoaiDon_ID", SqlDbType.TinyInt);
                        cmd.Parameters["@LoaiDon_ID"].Value = p.Loaidon_ID;
                        cmd.Parameters.Add("@LoaiHinhSX_ID", SqlDbType.Int);
                        cmd.Parameters["@LoaiHinhSX_ID"].Value = p.LoaiHinhSX_ID;
                        cmd.Parameters.Add("@ClientIP", SqlDbType.VarChar, 40);
                        cmd.Parameters["@ClientIP"].Value = p.ClientIP != null ? p.ClientIP : "";
                        cmd.Parameters.Add("@Code", SqlDbType.Int);
                        cmd.Parameters["@Code"].Direction = ParameterDirection.Output;
                        cmd.ExecuteNonQuery();
                        int code = int.Parse(cmd.Parameters["@Code"].Value.ToString());
                        LogClass.SaveDBLog("Result UpdateCustomer: " + code);
                        return(code);
                    }
                }
            }
            catch (Exception ex)
            {
                LogClass.SaveError("Error UpdateCustomer: " + ex.Message, ex, true);
                return((int)ERROR_CODDE.ERROR_EX);
            }
        }