コード例 #1
0
        //id为client的id
        public ActionResult AddContact(int id, int? clientid)
        {
            ClientActivity c = db.ClientActivities.Find(id);
            if (c != null)
            {
                if (c.PlanTime != null)
                {
                    return View("ShowError", "", "邀约记录不能通过这个入口修改");
                }
            }
            else
            {
                c = new ClientActivity { Person = UserInfo.CurUser.Id };
                c.ActualTime = DateTime.Now;
                c.ClientId = (int)clientid;
            }
            Client client = db.Clients.Find(c.ClientId);
            ViewBag.ProjectId = client.ProjectId;
            if (DepartmentBLL.GetById(client.GroupId).Name == "前台")
            {
                ViewBag.ChangeGroup = true;

            }
            return View(c);
        }
コード例 #2
0
        public ActionResult AddAppointment(int id, int? clientid,string ismobile, FormCollection collection)
        {
            ClientActivity c = new ClientActivity { Person = UserInfo.CurUser.Id };
            db.ClientActivities.Add(c);

            TryUpdateModel(c, collection);
            if (!c.PlanTime.HasValue)
            {
                ModelState.AddModelError("PlanTime", "邀约时间不能为空");
            }
            if (ModelState.IsValid)
            {
                db.SaveChanges();
                if (!string.IsNullOrEmpty(ismobile))
                {
                    return Redirect("../View/" + c.ClientId.ToString());
                }

                return Redirect("~/Content/close.htm");
            }
            else
            {
                return View(c);
            }
        }
コード例 #3
0
        public ActionResult AddContact(int id, int? clientid, string ismobile, FormCollection collection)
        {
            ClientActivity c = db.ClientActivities.Find(id);
            if (c != null)
            {
                if (c.PlanTime != null)
                {
                    return View("ShowError", "", "邀约记录不能通过这个入口修改");
                }
            }
            else
            {
                c = new ClientActivity();
                c.ClientId = (int)clientid;
                db.ClientActivities.Add(c);
            }
            TryUpdateModel(c, collection);
            if (c.Type == "on")
            {
                ModelState.AddModelError("Type", "请选择类型");
            }
            if (c.Id == 0 && c.Type == "来访")
            {
                if (!UserInfo.CurUser.HasRight("客户管理-客户来访记录"))
                {
                    return View("ShowError", "", "无权新增来访联系记录");
                }
            }
            if (!c.ActualTime.HasValue)
            {
                ModelState.AddModelError("ActualTime", "联系时间不能为空");
            }
            else if (((DateTime)c.ActualTime).Date != DateTime.Today)
            {
                ModelState.AddModelError("ActualTime", "联系日期只能为当天");
            }
            Client client = db.Clients.Find(c.ClientId);
            ViewBag.ProjectId = client.ProjectId;
            if (DepartmentBLL.GetById(client.GroupId).Name == "前台")
            {
                ViewBag.ChangeGroup = true;
                int group = 0;
                if (int.TryParse(collection["GroupId"], out group))
                {
                    client.GroupId = group;
                }
                else
                {
                    ModelState.AddModelError("", "请选择小组");
                    ViewBag.GroupPrompt = "请选择小组";
                }
            }
            if (ModelState.IsValid)
            {
                if (c.Type == "来访" && (client.State == ClientStateEnum.邀约客户 || client.State == ClientStateEnum.来电客户))
                {
                    client.State = ClientStateEnum.来访客户;
                    client.StateDate = DateTime.Today;
                    Utilities.AddLog(db, client.Id, Client.LogClass, "转来访客户", "");
                }
                if (c.Type == "来访")
                {
                    var logs = (from o in db.ClientActivities where o.ClientId == client.Id && o.Id != c.Id && o.FirstType == 2 select o).FirstOrDefault();
                    if (logs == null)
                    {
                        c.FirstType = 2;
                    }
                }
                db.SaveChanges();
                if (!string.IsNullOrEmpty(ismobile))
                {
                    return Redirect("../View/" + client.Id.ToString());
                }

                return Redirect("~/Content/close.htm");
            }
            else
            {
                return View(c);
            }
        }
コード例 #4
0
        public ActionResult Create(int projectid, int type, FormCollection collection)
        {
            ViewBag.QuDao = DictionaryBLL.GetL2ByName("渠道类型", true);
            ViewBag.HasAppointment = false;

            ViewBag.Type = type;
            bool HasAppointment = (collection["HasAppointment"] != null && collection["HasAppointment"].Equals("Add")) ? true : false;
            ViewBag.HasAppointment = HasAppointment;

            ClientCreate cc = new ClientCreate();
            cc.ProjectId = projectid;
            Project p = Project.Get(projectid);
            if (p.RoomTypes.Count > 0)
            {
                cc.RoomType = p.RoomTypes[0].Name;
            }
            switch (type)
            {
                case 1:
                    cc.GroupId = UserInfo.CurUser.GetGroup(projectid);
                    ViewBag.Msg = "来电客户登记"; break;
                case 2:
                    ViewBag.Msg = "直访客户登记";//直访客户要选择小组
                    if (!UserInfo.CurUser.HasRight("客户管理-前台"))//非前台不能做来访登记
                    {
                        return Redirect("~/content/AccessDeny.htm");
                    }
                    break;
                case 3:
                    cc.GroupId = UserInfo.CurUser.GetGroup(projectid);
                    ViewBag.HasAppointment = true;
                    ViewBag.QuDao = new List<Dictionary2>
                                    {
                                        new Dictionary2 {L1 = "中介", L2=new List<string>()}
                                    };
                    ViewBag.Msg = "中介邀约客户报备";
                    break;
                case 4:
                    cc.GroupId = Project.GetGroupByName(projectid, "前台");
                    ViewBag.HasAppointment = true;
                    ViewBag.QuDao = new List<Dictionary2>
                                    {
                                        new Dictionary2 {L1 = "电话中心", L2=new List<string>()}
                                    };
                    ViewBag.Msg = "电话中心客户报备";
                    //ToDo:如果邀约客户未到访,然后再次报备如何处理?
                    break;
                case 5:
                    cc.GroupId = UserInfo.CurUser.GetGroup(projectid);
                    ViewBag.HasAppointment = true;
                    ViewBag.QuDao = new List<Dictionary2>
                                    {
                                        new Dictionary2 {L1 = "销售员拓客", L2=new List<string>()}
                                    };
                    ViewBag.Msg = "销售员拓客报备";

                    break;
            }
            ClientStateEnum state = ClientStateEnum.邀约客户;
            TryUpdateModel(cc, collection);
            switch (type)
            {
                case 1:
                    state = ClientStateEnum.来电客户;
                    if (cc.AppointmentPlanTime != null || cc.AppointmentType != null)
                    {
                        if (cc.AppointmentPlanTime == null)
                        {
                            ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间");
                        }
                        if (cc.AppointmentType == null)
                        {
                            ModelState.AddModelError("AppointmentType", "请输入邀约类型");
                        }
                    }
                    break;
                case 2:
                    state = ClientStateEnum.来访客户;
                    if (cc.AppointmentPlanTime != null || cc.AppointmentType != null)
                    {
                        if (cc.AppointmentPlanTime == null)
                        {
                            ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间");
                        }
                        if (cc.AppointmentType == null)
                        {
                            ModelState.AddModelError("AppointmentType", "请输入邀约类型");
                        }
                    }
                    break;
                case 3:
                    state = ClientStateEnum.邀约客户;
                    if (cc.AppointmentPlanTime == null)
                    {
                        ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间");
                    }
                    if (cc.AppointmentType == null)
                    {
                        ModelState.AddModelError("AppointmentType", "请输入邀约类型");
                    }
                    break;

                case 4:
                    state = ClientStateEnum.邀约客户;
                    if (cc.AppointmentPlanTime == null)
                    {
                        ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间");
                    }
                    if (cc.AppointmentType == null)
                    {
                        ModelState.AddModelError("AppointmentType", "请输入邀约类型");
                    }
                    if (string.IsNullOrEmpty(cc.CallPerson))
                    {
                        ModelState.AddModelError("CallPerson", "请输入经办人");
                    }
                    break;
                case 5:
                    state = ClientStateEnum.邀约客户;
                    if (cc.AppointmentPlanTime == null)
                    {
                        ModelState.AddModelError("AppointmentPlanTime", "请输入邀约时间");
                    }
                    if (cc.AppointmentType == null)
                    {
                        ModelState.AddModelError("AppointmentType", "请输入邀约类型");
                    }

                    break;

            }
            Client checkClient = new Client
            {
                Id = cc.Id,
                ProjectId = cc.ProjectId,
                Phone1 = cc.Phone1,
                Phone2 = cc.Phone2
            };
            JsonResult numcheck = PhoneCheck(checkClient.Phone1);
            Result result = (Result)numcheck.Data;
            if (!result.success)
            {
                if (result.obj.Equals("号码格式错误"))
                    ModelState.AddModelError("Phone1", result.obj.ToString());
            }
            if (!string.IsNullOrEmpty(checkClient.Phone2))
            {
                numcheck = PhoneCheck(checkClient.Phone2);
                result = (Result)numcheck.Data;
                if (!result.success)
                {
                    if (result.obj.Equals("号码格式错误"))
                        ModelState.AddModelError("Phone2", result.obj.ToString());
                }
            }
            int check = CheckClientByPhone(checkClient);
            if (check != 0)
            {
                ModelState.AddModelError("", "同电话号码客户已经存在,所在组为:" + DepartmentBLL.GetNameById(check));
            }
            if (ModelState.IsValid)
            {
                Client c = new Client();
                UpdateModel(c, collection);
                c.ProjectId = cc.ProjectId;
                c.GroupId = cc.GroupId;
                c.CreateTime = DateTime.Now;
                c.StateDate = DateTime.Today;
                c.State = state;
                c.CallPerson = cc.CallPerson;
                db.Clients.Add(c);
                db.SaveChanges();
                ClientActivity ca = new ClientActivity { Person = UserInfo.CurUser.Id };
                ca.ClientId = c.Id;
                switch (type)
                {
                    case 1:
                        db.ClientActivities.Add(ca);
                        ca.ActualTime = DateTime.Today;
                        ca.Type = "来电";
                        ca.FirstType = 1;
                        break;
                    case 2:
                        db.ClientActivities.Add(ca);
                        ca.ActualTime = DateTime.Today;
                        ca.Type = "来访";
                        ca.FirstType = 2;
                        break;
                    case 3:
                    case 4:
                        break;
                }
                if (cc.AppointmentType != null)
                {
                    ClientActivity appoint = new ClientActivity { Person = UserInfo.CurUser.Id };
                    appoint.ClientId = c.Id;
                    appoint.PlanTime = cc.AppointmentPlanTime;
                    appoint.Type = cc.AppointmentType;
                    appoint.Detail = cc.AppointmentDetail;

                    db.ClientActivities.Add(appoint);
                }
                if (!string.IsNullOrEmpty(c.Phone2))
                    c.AllPhone = string.Format("{0},{1}", c.Phone1, c.Phone2);
                else
                    c.AllPhone = c.Phone1;
                Utilities.AddLog(db, c.Id, Client.LogClass, "客户登记", string.Format("{0} 姓名:{1} 电话:{2}", ca.Type ?? cc.AppointmentType, c.Name, c.AllPhone));
                c.Code = p.GetNewClientCode(db);
                db.SaveChanges();

                return Redirect("./View/" + c.Id);
                //ToDo:这个地方有BUG,提交不成功后出错
            }
            else
            {
                return View("Create", cc);
            }
        }
コード例 #5
0
 public ActionResult AddAppointment(int id, int? clientid)
 {
     ClientActivity c = new ClientActivity { Person = UserInfo.CurUser.Id };
     c.ClientId = (int)clientid;
     return View(c);
 }
コード例 #6
0
        public void Fun1(string filename)
        {
            FileInfo fi = new FileInfo(filename);
            StringBuilder errorinfo = new StringBuilder();
            using (ExcelPackage package = new ExcelPackage(fi))
            {
                ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"];
                int i = 1;
                using (Context db = new Context())
                {
                    //db.Configuration.AutoDetectChangesEnabled = false;
                    //using (TransactionScope tran = new TransactionScope())
                    //{
                    while (i < 6000)
                    {
                        i++;
                        string name = ExcelHelper.ReadString(worksheet.Cells[i, 3]);
                        if (string.IsNullOrEmpty(name)) continue;
                        int projectid = int.Parse(ExcelHelper.ReadString(worksheet.Cells[i, 9]));
                        DateTime? d = ExcelHelper.ReadDateEmpty(worksheet.Cells[i, 2]);
                        if (d == null)
                        {
                            Console.WriteLine("ErrorDate" + i.ToString());
                            continue;
                        }
                        string phone = ExcelHelper.ReadString(worksheet.Cells[i, 4]);
                        string way = ExcelHelper.ReadString(worksheet.Cells[i, 5]);
                        if (string.IsNullOrEmpty(way))
                        {
                            way = "-";
                        }
                        string roomtype = ExcelHelper.ReadString(worksheet.Cells[i, 6]);
                        //string u1 = ExcelHelper.ReadString(worksheet.Cells[i, 7]);
                        string u2 = ExcelHelper.ReadString(worksheet.Cells[i, 8]);
                        if (phone != "-")
                        {
                            if (
                            (from o in db.Clients where o.ProjectId == projectid && o.Phone1 == phone select o)
                                .FirstOrDefault() !=null)
                        {
                            Console.WriteLine("客户已存在" + i.ToString());
                            continue;
                        }
                        }

                        int sales1 = (from o in db.SystemUsers where o.Name == u2 select o.Id).FirstOrDefault();
                        int sales;
                        if (sales1 == 0)
                        {
                            Console.WriteLine("销售员不存在" + u2+i.ToString());
                            continue;
                        }
                        sales = (int) sales1;

                        int team1 =
                            (from o in db.SystemUsers
                                join p in db.DepartmentUsers on o.Id equals p.UserId
                                where o.Name == u2
                                select p.DepartmentId).FirstOrDefault();
                        if (team1 == 0)
                        {
                            Console.WriteLine("销售组不存在" + u2);
                            continue;
                        }
                        int team=(int)team1;
                        Client client = new Client {ProjectId = projectid};
                        client.Name = name;
                        client.Phone1 = phone;
                        client.Way = way;
                        client.RoomType = roomtype;
                        client.AllPhone = phone;
                        client.Code = "导入数据";
                        client.CreateTime = (DateTime)d;
                        client.GroupId = team;
                        client.State = ClientStateEnum.来电客户;
                        client.StateDate = new DateTime(2013, 11, 30);
                        db.Clients.Add(client);
                        db.SaveChanges();
                        ClientActivity ca = new ClientActivity {ClientId = client.Id};
                        db.ClientActivities.Add(ca);
                        ca.ActualTime = client.CreateTime;
                        ca.FirstType = 1;
                        ca.Person = sales;
                        ca.Type = "来电";
                        db.SaveChanges();

                          }
            //tran.Complete();
            //                    }
                }
            }
        }