예제 #1
0
        public JsonResult GetAgentInfo()
        {
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            int remainderDays = 0;
            int authorizeType = 0;

            if (Session["ClientManager"] != null)
            {
                var CurrentUser = (CloudSalesEntity.Users)Session["ClientManager"];
                var agent = AgentsBusiness.GetAgentDetail(CurrentUser.AgentID);

                remainderDays = (agent.EndTime - DateTime.Now).Days;
                authorizeType = agent.AuthorizeType;

            }

            JsonDictionary.Add("remainderDays", remainderDays);
            JsonDictionary.Add("authorizeType", authorizeType);

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #2
0
        public JsonResult GetUserOrders(int type,string userid, string teamid, string beginTime, string endTime,string ordertype)
        {

            var list = SalesRPTBusiness.BaseBusiness.GetUserOrders(userid, teamid, beginTime, endTime, CurrentUser.AgentID, CurrentUser.ClientID, ordertype);

            if (type == 2)
            {
                Dictionary<string, List<TypeOrderEntity>> customerlist =  new Dictionary<string, List<TypeOrderEntity>>(); 
                
                List<TypeOrderEntity> listcustomer = new List<TypeOrderEntity>();
                list.ForEach(x => listcustomer.AddRange(x.ChildItems));
                customerlist.Add("TotalList", listcustomer.OrderByDescending(x =>  x.TCount).Take(15).ToList());
                customerlist.Add("MoneyList", listcustomer.OrderByDescending(x =>  x.TMoney).Take(15).ToList());
                JsonDictionary.Add("items", customerlist);
            }
            else
            {
                JsonDictionary.Add("items", list);
            }
            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #3
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            if (filterContext.HttpContext.Response.StatusCode == 401)
            {
                string source = HttpContext.Current.Request.QueryString["source"];
                if (!string.IsNullOrEmpty(source) && source == "md")
                {
                    filterContext.Result = new RedirectResult("/Home/MDLogin?ReturnUrl=" + HttpContext.Current.Request.Url);
                }
                else 
                {
                    filterContext.Result = new RedirectResult("/Home/Login?ReturnUrl=" + HttpContext.Current.Request.Url);
                }
                return;
            }
            //else if (filterContext.HttpContext.Response.StatusCode == 402)
            //{
            //    filterContext.Result = new RedirectResult("/Home/Logout?Status=" + (int)EnumLoginStatus.OtherLogin);
            //}

            var controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();
            var action = filterContext.ActionDescriptor.ActionName.ToLower();
            var menu = CommonBusiness.ClientMenus.Where(m => m.Controller.ToLower() == controller && m.View.ToLower() == action).FirstOrDefault();

            //需要判断权限
            if (menu != null && menu.IsLimit == 1)
            {
                CloudSalesEntity.Users user = (CloudSalesEntity.Users)filterContext.HttpContext.Session["ClientManager"];
                if (user.Menus.Where(m => m.MenuCode == menu.MenuCode).Count() <= 0)
                {
                    if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
                    {
                        Dictionary<string, string> result = new Dictionary<string, string>();
                        result.Add("result", "10001");
                        result.Add("ErrMsg", "你暂无权限操作,请联系管理员.");
                        filterContext.Result = new JsonResult()
                        {
                            Data = result,
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        };
                    }
                    else
                    {
                        filterContext.RequestContext.HttpContext.Response.Write("<script>alert('您没有权限访问此页面');history.back();</script>");
                        filterContext.RequestContext.HttpContext.Response.End();
                    }
                }
            }

        }
예제 #4
0
        public JsonResult GetAgentActions()
        {
            CloudSalesEntity.Users CurrentUser = (CloudSalesEntity.Users)Session["ClientManager"];
            var model = LogBusiness.BaseBusiness.GetAgentActions(CurrentUser.AgentID);

            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            JsonDictionary.Add("model", model);

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #5
0
        /// <summary>
        /// 员工登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public JsonResult UserLogin(string userName, string pwd, string remember)
        {
            int result = 0;
            Dictionary<string, object> resultObj = new Dictionary<string, object>();
            YXERP.Common.PwdErrorUserEntity pwdErrorUser = null;

            if (Common.Common.CachePwdErrorUsers.ContainsKey(userName)) pwdErrorUser = Common.Common.CachePwdErrorUsers[userName];

            if (pwdErrorUser == null || (pwdErrorUser.ErrorCount < 3 && pwdErrorUser.ForbidTime<DateTime.Now) )
            {
                string operateip = string.IsNullOrEmpty(Request.Headers.Get("X-Real-IP")) ? Request.UserHostAddress : Request.Headers["X-Real-IP"];
                int outResult;
                CloudSalesEntity.Users model = CloudSalesBusiness.OrganizationBusiness.GetUserByUserName(userName, pwd, out outResult, operateip);
                if (model != null)
                {
                    //保持登录状态
                    HttpCookie cook = new HttpCookie("cloudsales");
                    cook["username"] = userName;
                    cook["pwd"] = pwd;
                    cook["status"] = remember;
                    cook.Expires = DateTime.Now.AddDays(7);
                    Response.Cookies.Add(cook);

                    Session["ClientManager"] = model;
                    Common.Common.CachePwdErrorUsers.Remove(userName);
                    result = 1;
                }
                else
                {
                    if (outResult == 3)
                    {
                        if (pwdErrorUser == null)
                            pwdErrorUser = new Common.PwdErrorUserEntity();
                        else
                        {
                            if (pwdErrorUser.ErrorCount > 2)
                                pwdErrorUser.ErrorCount = 0;
                        }

                        pwdErrorUser.ErrorCount += 1;
                        if (pwdErrorUser.ErrorCount > 2)
                        {
                            pwdErrorUser.ForbidTime = DateTime.Now.AddHours(2);
                            result = 2;
                        }
                        else
                        {
                            result = 3;
                            resultObj.Add("errorCount", pwdErrorUser.ErrorCount);
                        }

                        Common.Common.CachePwdErrorUsers[userName] = pwdErrorUser;
                    }

                }
            }
            else
            {
                int forbidTime =(int)(pwdErrorUser.ForbidTime - DateTime.Now).TotalMinutes;
                resultObj.Add("forbidTime", forbidTime);
                result = -1;
            }

            resultObj.Add("result",result);

            return new JsonResult
            {
                Data = resultObj,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #6
0
        /// <summary>
        /// 重置用户密码
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="loginPwd"></param>
        /// <returns></returns>
        public JsonResult UpdateUserPwd(string loginName, string loginPwd, string code)
        {
            int result = 0;
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();

            bool bl = OrganizationBusiness.IsExistLoginName(loginName);
            if (bl)
            {
                bl = Common.Common.ValidateMobilePhoneCode(loginName, code);
                if (!bl)
                {
                    result = 3;
                }
                else
                {
                    bl = OrganizationBusiness.UpdateUserAccountPwd(loginName, loginPwd);
                    result = bl ? 1 : 0;

                    if(bl)
                        Common.Common.ClearMobilePhoneCode(loginName);
                }

            }
            else
            {
                result = 2;
            }

            JsonDictionary.Add("Result",result);
            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #7
0
        /// <summary>
        /// 发送手机验证码
        /// </summary>
        /// <param name="mobilePhone"></param>
        /// <returns></returns>
        public JsonResult SendMobileMessage(string mobilePhone)
        {
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            Random rd = new Random();
            int code=rd.Next(100000, 1000000);

            bool flag = Common.MessageSend.SendMessage(mobilePhone, code);
            JsonDictionary.Add("Result",flag?1:0);

            if (flag)
            {
                Common.Common.SetCodeSession(mobilePhone, code.ToString());

                Common.Common.WriteAlipayLog(mobilePhone + " : " + code.ToString());

            }

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #8
0
        /// <summary>
        /// 主动注册客户端
        /// </summary>
        /// <param name="name"></param>
        /// <param name="companyName"></param>
        /// <param name="loginName"></param>
        /// <param name="loginPWD"></param>
        /// <returns></returns>
        public JsonResult RegisterClient(string name, string companyName, string loginName, string loginPWD,string code)
        {
            int result = 0;
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();

            bool bl = OrganizationBusiness.IsExistLoginName(loginName);
            if (bl){
                result = 2;
            }
            else
            {
                bl = Common.Common.ValidateMobilePhoneCode(loginName, code);
                if (!bl){
                    result = 3;
                }
                else
                {
                    Clients client = new Clients() { CompanyName=companyName,ContactName=name};
                    ClientBusiness.InsertClient(client, loginName, loginPWD, string.Empty, out result);

                    if (result == 1)
                    {
                        string operateip = Common.Common.GetRequestIP();
                        int outResult;
                        CloudSalesEntity.Users user = CloudSalesBusiness.OrganizationBusiness.GetUserByUserName(loginName, loginPWD, out outResult, operateip);
                        if (user != null){
                            Session["ClientManager"] = user;
                        }

                        Common.Common.ClearMobilePhoneCode(loginName);
                    }
                    else
                        result = 0;
                }
            }

            JsonDictionary.Add("Result", result);
            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #9
0
        /// <summary>
        /// 账号是否存在
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public JsonResult IsExistLoginName(string loginName)
        {
            bool bl = OrganizationBusiness.IsExistLoginName(loginName);
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            JsonDictionary.Add("Result", bl?1:0);

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #10
0
        /// <summary>
        /// 根据人数、年数获取最佳产品组合
        /// </summary>
        public JsonResult GetBestWay(int quantity, int years, int type)
        {
            int remainderMonths = 12;//剩余月份
            float discount = 1F;
            int pageCount = 0;
            int totalCount = 0;

            //购买人数
            if (type == 2)
            {
                remainderMonths = (CurrentAgent.EndTime.Year - DateTime.Now.Year) * 12 + (CurrentAgent.EndTime.Month - DateTime.Now.Month) - 1;
                if (CurrentAgent.EndTime.Day >= DateTime.Now.Day)
                    remainderMonths += 1;

                years = remainderMonths / 12 == 0 ? 1 : remainderMonths / 12;
                JsonDictionary.Add("PeriodQuantity", years);
            }

            List<ModulesProduct> list = ModulesProductBusiness.GetModulesProducts(string.Empty, int.MaxValue, 1, ref totalCount, ref pageCount);
            var way = ModulesProductBusiness.GetBestWay(quantity, list.OrderByDescending(m => m.UserQuantity).Where(m => m.PeriodQuantity == years).ToList());

            List<Dictionary<string, string>> products = new List<Dictionary<string, string>>();
            foreach (var p in way.Products)
            {
                Dictionary<string, string> product = new Dictionary<string, string>();
                product.Add("id", p.Key);
                product.Add("count", p.Value.ToString());
                products.Add(product);
            }

            JsonDictionary.Add("Items", products);
            JsonDictionary.Add("TotalMoney", way.TotalMoney);
            JsonDictionary.Add("TotalQuantity", way.TotalQuantity);


            //购买人数
            if (type == 2)
            {
                float remainderYears = (float)remainderMonths / (12 * years);
                JsonDictionary.Add("Amount", (float.Parse(way.TotalMoney.ToString()) * remainderYears).ToString("f2"));
            }

            if (!string.IsNullOrEmpty(CurrentUser.MDUserID))
            {
                if (type == 1 || type == 2)
                {
                    discount = 0.5F;
                }
                else
                {
                    discount = 0.88F;
                }

            }
            else
            {
                if (type == 1 || type == 2)
                {
                    discount = 0.66F;
                }
            }
            JsonDictionary.Add("Discount", discount);

            return new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #11
0
 public ActionResult CustomerImport(HttpPostedFileBase file, int overType = 0, int type=0)
 {
     if (file == null) { return Content("请选择要导入的文件"); }
     if (file.ContentLength > 2097152)
     {
         return Content("导入文件超过规定(2M )大小,请修改后再操作."); 
     }
     if (!file.FileName.Contains(".xls") && !file.FileName.Contains(".xlsx")) { return Content("文件格式类型不正确"); }
     string mes = "";
     try
     {
         DataTable dt = ImportExcelToDataTable(file);
         if (dt.Columns.Count > 0)
         {
             ///1.获取系统模版列
             var checkColumn = dt.Columns.Contains("是否企业客户");
             Dictionary<string, ExcelFormatter> dic = new Dictionary<string, ExcelFormatter>();
             Dictionary<string, ExcelModel> listColumn = GetColumnForJson("customer", ref dic, checkColumn ? "Item" : "OwnItem", "import", CurrentUser.ClientID);
             ///2.上传Excel 与模板中列是否一致 不一致返回提示
             foreach (DataColumn dc in dt.Columns)
             {
                 if (default(KeyValuePair<string, ExcelModel>).Equals(listColumn.FirstOrDefault(x => x.Value.Title == dc.ColumnName)))
                 {
                     mes += dc.ColumnName + ",";
                 }
             }
             if (!string.IsNullOrEmpty(mes))
             {
                 return Content("Excel模版与系统模版不一致,请重新下载模板,编辑后再上传.错误:缺少列 " + mes);
             } 
             ///3.开始处理
             int k = 1;
             List<CustomerEntity> list = new List<CustomerEntity>();
             List<ContactEntity> contactList = new List<ContactEntity>();
             var excelWriter = new ExcelWriter();
             foreach (DataRow dr in dt.Rows)
             {
                 try
                 {
                     if (checkColumn)
                     {
                         CustomerEntity customer = new CustomerEntity();
                         excelWriter.GetProductByDataRow(dr, listColumn, customer, dic, CurrentUser.ClientID);
                         customer.ClientID = CurrentUser.ClientID;
                         customer.AgentID = CurrentUser.AgentID;
                         customer.CreateUserID = CurrentUser.UserID;
                         customer.CreateTime = DateTime.Now;
                         customer.CustomerID = Guid.NewGuid().ToString();
                         customer.CityCode = GetCityCode(dr);
                         customer.OwnerID = customer.OwnerID.Trim() == "是" ? CurrentUser.UserID : "";
                         list.Add(customer);
                         //上面出问题的话请注释以上 使用下面
                         //list.Add(GetCustomerByDataRow(dr));
                     }
                     else
                     {
                         ContactEntity contact = new ContactEntity();
                         excelWriter.GetProductByDataRow(dr, listColumn, contact, dic, CurrentUser.ClientID);
                         contact.CityCode = GetCityCode(dr);
                         contact.ClientID = CurrentUser.ClientID;
                         contact.AgentID = CurrentUser.AgentID;
                         contact.CreateUserID = CurrentUser.UserID;
                         contact.OwnerID = CurrentUser.UserID;
                         contact.CustomerID = ""; 
                         contact.CreateTime = DateTime.Now;
                         contact.Type = 0;
                         contact.ContactID = Guid.NewGuid().ToString();
                         contactList.Add(contact);
                         //contactList.Add( GetContactByDataRow(dr, checkColumn));
                     }
                 }
                 catch (Exception ex)
                 {
                     mes += k +" 原因:"+ex.Message+ ",";
                 }
             }
             try
             {
                 if (list.Count > 0) ExcelImportBusiness.InsertCustomer(list, type, overType);
                 if (contactList.Count > 0) ExcelImportBusiness.InsertContact(contactList, type, overType);
             }
             catch (Exception ex)
             {
                 return Content("系统异常:请联系管理员,错误原因" + ex.Message);
             }
         }
         if (!string.IsNullOrEmpty(mes))
         {
             return Content("部分数据未导入成功,Excel行位置" + mes);
         }
     }
     catch (Exception ex)
     {
         return Content("系统异常:请联系管理员,错误原因:" + ex.Message.ToString());
     }
     return Content("操作成功");
 }
예제 #12
0
        public ActionResult ExportFromCustomer(bool test = false, string model = "", string filleName = "企业客户", string filter="")
        {
            Dictionary<string, ExcelFormatter> dic = new Dictionary<string, ExcelFormatter>();
             FilterCustomer qicCustomer =new FilterCustomer();
             Dictionary<string, ExcelModel> listColumn = new Dictionary<string, ExcelModel>();
            if (string.IsNullOrEmpty(filter))
            {
                listColumn = GetColumnForJson("customer", ref dic, model, test ? "testexport" : "export", CurrentUser.ClientID);
            }
            else
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer(); 
                qicCustomer=serializer.Deserialize<FilterCustomer>(filter);
                listColumn = GetColumnForJson("customer", ref dic, !string.IsNullOrEmpty(model) ? model : qicCustomer.ExcelType == 0 ? "Item" : "OwnItem", test ? "testexport" : "export", CurrentUser.ClientID);
            }
            var excelWriter = new ExcelWriter();
            foreach (var key in listColumn)
            {
                excelWriter.Map(key.Key, key.Value.Title);
            }
            byte[] buffer;
            DataTable dt = new DataTable();
            //模版导出
            if (test)
            {
                DataRow dr = dt.NewRow();
                foreach (var key in listColumn)
                {
                    DataColumn dc1 = new DataColumn(key.Key, Type.GetType("System.String"));
                    dt.Columns.Add(dc1);
                    if (key.Key == "extent")
                    {
                        dr[key.Key] = "下拉框中选择";
                    }
                    else if (key.Key == "industryid")
                    {
                        dr[key.Key] = "下拉框中选择";
                    }
                    else if (key.Key == "province")
                    {
                        dr[key.Key] = "下拉框中选择";
                    }
                    else
                    {
                        dr[key.Key] = key.Value.DefaultText;
                    }
                }
                dt.Rows.Add(dr);
            }
            else
            {
                int totalCount = 0;
                int pageCount = 0; 
                //客户
                dt = CustomBusiness.BaseBusiness.GetCustomersDatable(qicCustomer.SearchType, qicCustomer.Type,
                    qicCustomer.SourceID, qicCustomer.StageID, qicCustomer.Status, qicCustomer.Mark,
                    qicCustomer.ActivityID, qicCustomer.UserID, qicCustomer.TeamID, qicCustomer.AgentID,
                    qicCustomer.BeginTime, qicCustomer.EndTime,
                    qicCustomer.Keywords, qicCustomer.OrderBy, int.MaxValue, 1, ref totalCount, ref pageCount,
                    CurrentUser.UserID, CurrentUser.AgentID, CurrentUser.ClientID, qicCustomer.ExcelType);
                if (!dt.Columns.Contains("province"))
                {
                    dt.Columns.Add("province", Type.GetType("System.String"));
                }
                if (!dt.Columns.Contains("citys"))
                {
                    dt.Columns.Add("citys", Type.GetType("System.String"));
                }
                if (!dt.Columns.Contains("counties"))
                {
                    dt.Columns.Add("counties", Type.GetType("System.String"));
                }
                foreach (DataRow drRow in dt.Rows)
                {
                    var city=  CommonBusiness.GetCityByCode(drRow["CityCode"].ToString());
                    if (city != null)
                    {
                        drRow["province"] = city.Province;
                        drRow["citys"] = city.City;
                        drRow["counties"] = city.Counties;
                    }
                }
            }
            buffer = excelWriter.Write(dt, dic);
            var fileName = filleName + (test ? "导入模版" : "") + DateTime.Now.ToString("yyyyMMdd");
            if (!Request.ServerVariables["http_user_agent"].ToLower().Contains("firefox"))
                fileName = HttpUtility.UrlEncode(fileName);
            this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx");
            return File(buffer, "application/ms-excel");

        }
예제 #13
0
        public ActionResult ExportFromCfg()
        {
            var excelWriter = new ExcelWriter();
            Dictionary<string, object> listColumn = new Dictionary<string, object>();
            excelWriter.Map("Name", "公司名称");
            excelWriter.Map("Contcat", "客户名称");
            excelWriter.Map("Jobs", "职位");
            excelWriter.Map("MobilePhone", "联系电话");
            excelWriter.Map("Email", "邮箱");
            excelWriter.Map("Province", "省");
            excelWriter.Map("City", "市");
            excelWriter.Map("District", "区");
            excelWriter.Map("Address", "详细地址");
            excelWriter.Map("Description", "描述");
          
            byte[] buffer = excelWriter.Write(OrganizationBusiness.GetUserById(CurrentUser.UserID),
                new Dictionary<string, ExcelFormatter>()
                {
                    {
                        "birthday", new ExcelFormatter()
                        {
                            ColumnTrans = EnumColumnTrans.ConvertTime,
                            DropSource = ""

                        }
                    }
                });
            var fileName = "客户信息导入";
            if (!Request.ServerVariables["http_user_agent"].ToLower().Contains("firefox"))
                fileName = HttpUtility.UrlEncode(fileName);
            this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx");
            return File(buffer, "application/ms-excel");
        }
예제 #14
0
        public ActionResult ProductImport(HttpPostedFileBase file)
        {
            string mes = "";
            if (file == null) { return Content("请选择要导入的文件"); }
            if (file.ContentLength > 2097152)
            {
                return Content("导入文件超过规定(2M )大小,请修改后再操作.");
            }
            if (!file.FileName.Contains(".xls") && !file.FileName.Contains(".xlsx"))
            {
                return Content("文件格式类型不正确");
            }
            try
            {
                DataTable dt = ImportExcelToDataTable(file);
                if (dt.Columns.Count > 0)
                {
                    ///1.获取系统模版列 
                    Dictionary<string, ExcelFormatter> dic=new Dictionary<string, ExcelFormatter>();
                    Dictionary<string, ExcelModel> listColumn = GetColumnForJson("product", ref dic, "",  "import", CurrentUser.ClientID);
                    ;//GetColumnForJson("product", "Item");
                    ///2.上传Excel 与模板中列是否一致 不一致返回提示
                    foreach (DataColumn dc in dt.Columns)
                    {
                        if (default(KeyValuePair<string, ExcelModel>).Equals(listColumn.FirstOrDefault(x => x.Value.Title == dc.ColumnName)))
                        {
                            mes += dc.ColumnName + ",";
                        }
                    }
                    if (!string.IsNullOrEmpty(mes))
                    {
                        return Content("Excel模版与系统模版不一致,请重新下载模板,编辑后再上传.错误:缺少列 " + mes);
                    }
                    ///3.开始处理
                    int k = 1;
                    var excelWriter = new ExcelWriter();
                    List<Products> list = new List<Products>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        try
                        {
                            Products product=new Products();
                            excelWriter.GetProductByDataRow(dr, listColumn, product,dic,CurrentUser.ClientID);
                            product.CreateUserID = CurrentUser.UserID;
                            product.ClientID = CurrentUser.ClientID;
                            product.BigUnitID = "";
                            list.Add(product);
                        }
                        catch (Exception ex)
                        {
                            mes += k +" 原因:"+ex.Message+ ",";
                        }
                    }
                    try
                    {
                        if (list.Count > 0)
                        {
                            mes= ExcelImportBusiness.InsertProduct(list);
                        }
                        if (!string.IsNullOrEmpty(mes))
                        {
                            return Content("部分数据未导入成功,原因如下 :" + mes);
                        }
                        else
                        {
                            return Content("操作成功");
                        }
                    }
                    catch (Exception ex)
                    {
                        return Content("系统异常:请联系管理员,错误原因" + ex.Message);
                    }

                }
                if (!string.IsNullOrEmpty(mes))
                {
                    return Content("部分数据未导入成功,Excel行位置" + mes);
                }
            }
            catch (Exception ex)
            {
                return Content("系统异常:请联系管理员,错误原因:" + ex.Message.ToString());
            }
            return Content(mes);
        } 
예제 #15
0
        public ActionResult ExportFromProduct(bool test = false, string model = "", string filleName = "产品", string filter = "")
        {
            JavaScriptSerializer serializer=new JavaScriptSerializer();
            Dictionary<string, ExcelFormatter> dic = new Dictionary<string, ExcelFormatter>();
            FilterProduct qicProduct =  serializer.Deserialize<FilterProduct>(filter);
            Dictionary<string, ExcelModel> listColumn = new Dictionary<string, ExcelModel>();
            if (string.IsNullOrEmpty(filter))
            {
                listColumn = GetColumnForJson("product", ref dic, model, test ? "testexport" : "export", CurrentUser.ClientID);
            }
            else
            {  
                qicProduct = serializer.Deserialize<FilterProduct>(filter);
                listColumn = GetColumnForJson("product", ref dic, !string.IsNullOrEmpty(model) ? model : "Item", test ? "testexport" : "export", CurrentUser.ClientID);
            }
            string ipPath = "";
            var excelWriter = new ExcelWriter();
            foreach (var key in listColumn)
            {
                excelWriter.Map(key.Key, key.Value.Title);
            }
            byte[] buffer;
            DataTable dt = new DataTable();
            //模版导出
            if (test)
            {
                DataRow dr = dt.NewRow();
                foreach (var key in listColumn)
                {
                    DataColumn dc1 = new DataColumn(key.Key, Type.GetType("System.String"));
                    dt.Columns.Add(dc1); 
                    dr[key.Key] = key.Value.DefaultText; 
                }
                dt.Rows.Add(dr);
            }
            else
            {
                int totalCount = 0;
                int pageCount = 0; 
                ipPath= Server.MapPath("~");
                dt = new ProductsBusiness().GetProductListDataTable(qicProduct.CategoryID, qicProduct.BeginPrice, qicProduct.EndPrice, qicProduct.Keywords, qicProduct.OrderBy, qicProduct.IsAsc, PageSize, qicProduct.PageIndex, ref totalCount, ref pageCount, CurrentUser.ClientID);

            }
            buffer = excelWriter.Write(dt, dic, ipPath);
            var fileName = filleName + (test ? "导入模版" : "")+DateTime.Now.ToString("yyyyMMdd");
            if (!Request.ServerVariables["http_user_agent"].ToLower().Contains("firefox"))
                fileName = HttpUtility.UrlEncode(fileName);
            this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx");
            return File(buffer, "application/ms-excel");

        }
예제 #16
0
        /// <summary>
        /// 验证手机验证码
        /// </summary>
        /// <param name="mobilePhone"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public JsonResult ValidateMobilePhoneCode(string mobilePhone, string code)
        {
            bool bl = Common.Common.ValidateMobilePhoneCode(mobilePhone, code);
            Dictionary<string, object> JsonDictionary = new Dictionary<string, object>();
            JsonDictionary.Add("Result", bl ? 1 : 0);

            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #17
0
        public Products GetProductByID(string productid)
        {
            var dal = new ProductsDAL();
            DataSet ds = dal.GetProductByID(productid);

            Products model = new Products();
            if (ds.Tables.Contains("Product") && ds.Tables["Product"].Rows.Count > 0)
            {
                model.FillData(ds.Tables["Product"].Rows[0]);
                model.Category = GetCategoryDetailByID(model.CategoryID);
                var bigunit = new ProductUnit();
                bigunit.FillData(ds.Tables["Unit"].Select("UnitID='" + model.BigUnitID + "'").FirstOrDefault());
                model.BigUnit = bigunit;

                var smallunit = new ProductUnit();
                smallunit.FillData(ds.Tables["Unit"].Select("UnitID='" + model.SmallUnitID + "'").FirstOrDefault());
                model.SmallUnit = smallunit;

                model.ProductDetails = new List<ProductDetail>();
                foreach (DataRow item in ds.Tables["Details"].Rows)
                {
                    //子产品
                    ProductDetail detail = new ProductDetail();
                    detail.FillData(item);

                    Dictionary<string, string> attrs = new Dictionary<string, string>();
                    foreach (string attr in detail.SaleAttrValue.Split(','))
                    {
                        if (!string.IsNullOrEmpty(attr))
                        {
                            attrs.Add(attr.Split(':')[0], attr.Split(':')[1]);
                        }
                    }
                    detail.SaleAttrValueString = "";
                    foreach (var attr in model.Category.SaleAttrs)
                    {
                        if (attrs.ContainsKey(attr.AttrID))
                        {
                            detail.SaleAttrValueString += attr.AttrName + ":" + attr.AttrValues.Where(a => a.ValueID.ToLower() == attrs[attr.AttrID].ToLower()).FirstOrDefault().ValueName + ",";
                        }
                    }

                    if (detail.SaleAttrValueString.Length > 0)
                    {
                        detail.SaleAttrValueString = detail.SaleAttrValueString.Substring(0, detail.SaleAttrValueString.Length - 1);
                    }

                    model.ProductDetails.Add(detail);
                }
            }

            return model;
        }
예제 #18
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public JsonResult UploadFile()
        {
            string oldPath = "",
                   folder = CloudSalesTool.AppSettings.Settings["UploadTempPath"], 
                   action = "";
            if (Request.Form.AllKeys.Contains("oldPath"))
            {
                oldPath = Request.Form["oldPath"];
            }
            if (Request.Form.AllKeys.Contains("folder") && !string.IsNullOrEmpty(Request.Form["folder"]))
            {
                folder = Request.Form["folder"];
            }
            string uploadPath = HttpContext.Server.MapPath(folder);

            if (Request.Form.AllKeys.Contains("action"))
            {
                action = Request.Form["action"];
            }
            if (!Directory.Exists(uploadPath))
            {
                Directory.CreateDirectory(uploadPath);
            }
            List<string> list = new List<string>();
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i];
                //判断图片类型
                string ContentType = file.ContentType;
                Dictionary<string, string> types = new Dictionary<string, string>();
                types.Add("image/x-png", "1");
                types.Add("image/png", "1");
                types.Add("image/gif", "1");
                types.Add("image/jpeg", "1");
                types.Add("image/tiff", "1");
                types.Add("application/x-MS-bmp", "1");
                types.Add("image/pjpeg", "1");
                if (!types.ContainsKey(ContentType))
                {
                    continue;
                }
                if (file.ContentLength > 1024 * 1024 * 10)
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(oldPath) && oldPath != "/modules/images/default.png" && new FileInfo(HttpContext.Server.MapPath(oldPath)).Exists)
                {
                    file.SaveAs(HttpContext.Server.MapPath(oldPath));
                    list.Add(oldPath);
                   
                }
                else 
                {
                    string[] arr = file.FileName.Split('.');
                    string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms") + new Random().Next(1000, 9999).ToString() + "." + arr[arr.Length - 1];
                    string filePath = uploadPath + fileName;
                    file.SaveAs(filePath);
                    list.Add(folder + fileName);
                }
            }

            JsonDictionary.Add("Items", list);
            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
예제 #19
0
        public JsonResult GetUserCustomers(string UserID, string TeamID, string beginTime, string endTime,int type=0)
        {

            var list = CustomerRPTBusiness.BaseBusiness.GetUserCustomers(UserID, TeamID, beginTime, endTime, CurrentUser.AgentID, CurrentUser.ClientID);

            if (type == 6)
            {
                Dictionary<string, List<StageCustomerEntity>> customerlist =
                          new Dictionary<string, List<StageCustomerEntity>>();
                if (!string.IsNullOrEmpty(UserID))
                {
                    customerlist.Add("TotalList", list);
                    customerlist.Add("SCSRList", list);
                    customerlist.Add("OCSRList", list);
                    customerlist.Add("NCSRList", list);
                }
                else
                {
                    List<StageCustomerEntity> listcustomer = new List<StageCustomerEntity>();
                    list.ForEach(x => listcustomer.AddRange(x.ChildItems));
                    customerlist.Add("TotalList", listcustomer.OrderByDescending(x => x.TotalNum).Take(15).ToList());
                    customerlist.Add("SCSRList", listcustomer.OrderByDescending(x => x.SCSRNum).Take(15).ToList());
                    customerlist.Add("OCSRList", listcustomer.OrderByDescending(x => x.OCSRNum).Take(15).ToList());
                    customerlist.Add("NCSRList", listcustomer.OrderByDescending(x => x.NCSRNum).Take(15).ToList());
                } 
                JsonDictionary.Add("items", customerlist);
            }
            else
            {
                JsonDictionary.Add("items", list);
            }
            return new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }