public string CheckThongTinKhachHang(Add_Bill item)
        {
            string rs = null;

            if (string.IsNullOrEmpty(item.tenkh))
            {
                return(rs = "Tên khách hàng không được để trống");
            }
            if (string.IsNullOrEmpty(item.dienthoai))
            {
                return(rs = "SĐT khách hàng không được để trống");
            }

            var checkKH =
                db.service_customer.FirstOrDefault(m => m.fullname == item.tenkh && m.mobile == item.dienthoai);

            if (checkKH == null)
            {
                service_customer inew = new service_customer();
                inew.fullname    = item.tenkh;
                inew.mobile      = item.dienthoai;
                inew.address     = item.diachi;
                inew.id_center   = item.id_center;
                inew.code_center = item.code_center;
                inew.created_at  = DateTime.Now;
                inew.created_by  = item.tennguoithaotac;
                inew.status      = 1;
                inew.note        = "Thêm mới khách hàng khi bán đại lý";
                db.service_customer.Add(inew);
                db.SaveChanges();
            }

            return(null);
        }
        public ActionResult _AddCustomer(string fullName, string cmt, string birth, string address, string phone, string note, int branchId = 0)
        {
            // kiểm tra quyền thêm
            var sys = CheckActiveMenu.ReturnActive(SystemMessageConst.TypeAction.Addnew);

            if (sys.IsSuccess == false)
            {
                return(Json(new { result = sys }, JsonRequestBehavior.AllowGet));
            }

            var db = new CustomerBusiness();

            service_customer serviceCustomer = new service_customer();


            var getbrand = entity.Branch.FirstOrDefault(m => m.Id == branchId);

            serviceCustomer.fullname    = fullName;
            serviceCustomer.id_card     = cmt;
            serviceCustomer.address     = address;
            serviceCustomer.mobile      = phone;
            serviceCustomer.note        = note;
            serviceCustomer.status      = 1;
            serviceCustomer.id_center   = branchId;
            serviceCustomer.code_center = getbrand.Branch_code;
            serviceCustomer.created_by  = user.FullName;
            serviceCustomer.created_at  = DateTime.Now;

            DateTime _birth;

            if (!string.IsNullOrEmpty(birth))
            {
                if (!DateTime.TryParseExact(birth, "dd/MM/yyyy", CultureInfo.InvariantCulture,
                                            DateTimeStyles.None, out _birth))
                {
                    SystemMessage systemMessage = new SystemMessage();
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = string.Format(SystemMessageConst.ValidateConst.DateIsNotValid, "Ngày sinh");
                    return(Json(new { result = systemMessage }, JsonRequestBehavior.AllowGet));
                }
                serviceCustomer.birthday = _birth;
            }
            var result = db.AddCustomer(serviceCustomer);

            // luu log - thêm mới
            CheckRuleAndSaveLog.ReturnCheckRuleAndSaveLog(DbLogType.Create.ToString(), result.IsSuccess, JsonConvert.SerializeObject(new { data = serviceCustomer }, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));


            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public SystemMessage AddCustomer(service_customer customer)
        {
            SystemMessage systemMessage = new SystemMessage();

            try
            {
                var check = ValidateCustomer(customer);
                if (check != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = check;
                    return(systemMessage);
                }

                var checkBranch = db.Branch.FirstOrDefault(ob => ob.Id == customer.id_center);
                if (checkBranch == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Đại lý không tồn tại !!!!";
                    return(systemMessage);
                }

                var checkSDT = db.service_customer.FirstOrDefault(m => m.mobile == customer.mobile && m.id_center == customer.id_center);
                if (checkSDT != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "SĐT đã tồn tại";
                    return(systemMessage);
                }
                var checkCMT = db.service_customer.FirstOrDefault(m => m.id_card == customer.id_card && m.id_center == customer.id_center);
                if (checkCMT != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "CMT đã tồn tại";
                    return(systemMessage);
                }

                db.service_customer.Add(customer);
                db.SaveChanges();
                systemMessage.IsSuccess = true;
                systemMessage.Message   = SystemMessageConst.systemmessage.AddSuccess;
                return(systemMessage);
            }
            catch (Exception e)
            {
                systemMessage.IsSuccess = false;
                systemMessage.Message   = e.ToString();
                return(systemMessage);
            }
        }
Exemplo n.º 4
0
        public Customer_Pagelist ListCustomer(string searchValue, int currPage, int recodperpage, int centerid, int roleid)
        {
            Customer_Pagelist result = new Customer_Pagelist();

            List <service_customer> list = new List <service_customer>();
            SqlConnection           con  = new SqlConnection();

            con = Connection.Connect.GetConnect();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "sp_customer_getall";
            cmd.Parameters.Add(new SqlParameter("@searchValue", searchValue));
            cmd.Parameters.Add(new SqlParameter("@centerid", centerid));
            cmd.Parameters.Add(new SqlParameter("@roleid", roleid));
            cmd.Parameters.Add(new SqlParameter("@roleadmin", SystemMessageConst.Role.Admin));
            cmd.Parameters.Add(new SqlParameter("@currPage", currPage));
            cmd.Parameters.Add(new SqlParameter("@recodperpage", 10));
            cmd.Parameters.Add("@totalCount", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable      dt = new DataTable();

            da.Fill(dt);
            int total = Convert.ToInt32(cmd.Parameters["@totalCount"].Value);

            foreach (DataRow rowItem in dt.Rows)
            {
                service_customer customer = new service_customer();
                customer.id        = Int32.Parse(rowItem["id"].ToString());
                customer.id_center = Int32.Parse(rowItem["id_center"].ToString());
                customer.fullname  = rowItem["fullname"].ToString();
                customer.id_card   = rowItem["id_card"].ToString();
                customer.address   = rowItem["address"].ToString();
                customer.mobile    = rowItem["mobile"].ToString();
                customer.note      = rowItem["note"].ToString();
                if (rowItem["birthday"].ToString() != "")
                {
                    customer.birthday = DateTime.Parse(rowItem["birthday"].ToString());
                }
                list.Add(customer);
            }

            result.Data  = list;
            result.Total = total;
            return(result);
        }
        public ActionResult _EditCustomer(string fullName, string cmt, string birth, string address, string phone, string note, int branchId = 0, int id = 0)
        {
            // kiểm tra quyền thêm sửa
            var sys = CheckActiveMenu.ReturnActive(SystemMessageConst.TypeAction.Update);

            if (sys.IsSuccess == false)
            {
                return(Json(new { result = sys }, JsonRequestBehavior.AllowGet));
            }



            var db = new CustomerBusiness();
            service_customer serviceCustomer = new service_customer();

            serviceCustomer.fullname  = fullName;
            serviceCustomer.id_card   = cmt;
            serviceCustomer.address   = address;
            serviceCustomer.mobile    = phone;
            serviceCustomer.note      = note;
            serviceCustomer.id_center = branchId;
            serviceCustomer.id        = id;

            DateTime _birth;

            if (!string.IsNullOrEmpty(birth))
            {
                if (!DateTime.TryParseExact(birth, "dd/MM/yyyy", CultureInfo.InvariantCulture,
                                            DateTimeStyles.None, out _birth))
                {
                    SystemMessage systemMessage = new SystemMessage();
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = string.Format(SystemMessageConst.ValidateConst.DateIsNotValid, "Ngày sinh");
                    return(Json(new { result = systemMessage }, JsonRequestBehavior.AllowGet));
                }
                serviceCustomer.birthday = _birth;
            }
            var result = db.EditCustomer(serviceCustomer);

            CheckRuleAndSaveLog.ReturnCheckRuleAndSaveLog(DbLogType.Update.ToString(), result.IsSuccess, JsonConvert.SerializeObject(new { log = "CapNhatThongTinKH", newtdata = serviceCustomer }, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));


            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        public string ValidateCustomer(service_customer customer)
        {
            string rs  = null;
            var    vld = new ValidateUtils();

            rs = vld.CheckRequiredField(customer.fullname, "Họ và tên", 3, 50);
            if (rs != null)
            {
                return(rs);
            }
            rs = vld.CheckRequiredField(customer.id_card, "Số chứng minh thư", 7, 25);
            if (rs != null)
            {
                return(rs);
            }
            //rs = vld.CheckRequiredField(customer.code_customer, "Mã khách hàng", 3, 25);
            //if (rs != null)
            //{
            //    return rs;
            //}
            rs = vld.CheckRequiredField(customer.address, "Địa chỉ", 3, 100);
            if (rs != null)
            {
                return(rs);
            }
            rs = vld.CheckRequiredField(customer.mobile, "Số điện thoại", 9, 15);
            if (rs != null)
            {
                return(rs);
            }
            rs = vld.CheckNonRequiredField(customer.note, "Ghi chú", 250);
            if (rs != null)
            {
                return(rs);
            }
            return(null);
        }
Exemplo n.º 7
0
        public SystemMessage EditCustomer(service_customer customer)
        {
            SystemMessage systemMessage = new SystemMessage();

            try
            {
                var check = ValidateCustomer(customer);
                if (check != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = check;
                    return(systemMessage);
                }

                var checkExisted = db.service_customer.FirstOrDefault(ob => ob.id == customer.id && ob.id_center == customer.id_center);
                if (checkExisted == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = SystemMessageConst.systemmessage.NoData;
                    return(systemMessage);
                }
                var checkBranch = db.Branch.FirstOrDefault(ob => ob.Id == customer.id_center);
                if (checkBranch == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Đại lý không tồn tại !!!!";
                    return(systemMessage);
                }

                var checkSDT = db.service_customer.FirstOrDefault(m => m.mobile == customer.mobile && m.id != customer.id && m.id_center == customer.id_center);
                if (checkSDT != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "SĐT đã tồn tại";
                    return(systemMessage);
                }
                var checkCMT = db.service_customer.FirstOrDefault(m => m.id_card == customer.id_card && m.id != customer.id && m.id_center == customer.id_center);
                if (checkCMT != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "CMT đã tồn tại";
                    return(systemMessage);
                }

                checkExisted.fullname = customer.fullname;
                checkExisted.address  = customer.address;

                checkExisted.note = customer.note;

                checkExisted.id_card   = customer.id_card;
                checkExisted.note      = customer.note;
                checkExisted.birthday  = customer.birthday;
                checkExisted.id_center = customer.id_center;

                checkExisted.mobile = customer.mobile;

                db.SaveChanges();
                systemMessage.IsSuccess = true;
                systemMessage.Message   = SystemMessageConst.systemmessage.EditSuccess;
                return(systemMessage);
            }
            catch (Exception e)
            {
                systemMessage.IsSuccess = false;
                systemMessage.Message   = e.ToString();
                return(systemMessage);
            }
        }