Ejemplo n.º 1
0
        public ActionResult NewAccount()
        {
            string strErrText;

            //生成组织部门下拉列表项
            OrganizationSystem organ = new OrganizationSystem();
            List<Organization> listOrganization = organ.LoadOrganizations(LoginAccountId, LoginStaffName, out strErrText);
            if (listOrganization == null)
            {
                throw new Exception(strErrText);
            }
            List<SelectListItem> selectListOrganization = new List<SelectListItem>();
            selectListOrganization.Add(new SelectListItem { Text = string.Empty, Value = "0" });
            selectListOrganization.AddRange(from o in listOrganization
                                            orderby o.FullName
                                            select new SelectListItem
                                            {
                                                Text = o.FullName,
                                                Value = o.Id.ToString()
                                            });
            ViewData["Organizations"] = new SelectList(selectListOrganization, "Value", "Text");

            //生成空的员工下拉列表项
            List<Staff> listStaff = new List<Staff>();
            List<SelectListItem> selectListStaff = new List<SelectListItem>();
            selectListStaff.Add(new SelectListItem { Text = string.Empty, Value = "0" });
            selectListStaff.AddRange(from s in listStaff
                                     select new SelectListItem
                                     {
                                         Text = s.Name,
                                         Value = s.Id.ToString()
                                     });
            ViewData["Staffs"] = new SelectList(selectListStaff, "Value", "Text");

            //生成空的客户下拉列表项
            List<Customer> listCustomer = new List<Customer>();
            List<SelectListItem> selectListCustomer = new List<SelectListItem>();
            selectListCustomer.Add(new SelectListItem { Text = string.Empty, Value = "0" });
            selectListCustomer.AddRange(from c in listCustomer
                                        select new SelectListItem
                                        {
                                            Text = c.Name,
                                            Value = c.Id.ToString()
                                        });
            ViewData["Customers"] = new SelectList(selectListCustomer, "Value", "Text");

            //创建空的Model
            AccountViewModel model = new AccountViewModel();

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult NewAccount(AccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.AccountType == InnoSoft.LS.Resources.Options.Staff)
                {
                    if (model.OrganId == 0)
                    {
                        return Json(InnoSoft.LS.Resources.Strings.NotSelectedOrgan);
                    }
                    if (model.StaffId == 0)
                    {
                        return Json(InnoSoft.LS.Resources.Strings.NotSelectedStaff);
                    }
                }
                else
                {
                    if (model.CustomerId == 0)
                    {
                        return Json(InnoSoft.LS.Resources.Strings.NotSelectedCustomer);
                    }
                    if (model.ContactName.Trim() == string.Empty)
                    {
                        return Json(InnoSoft.LS.Resources.Strings.NotEnterContactName);
                    }
                }

                //创建数据
                Account data = new Account();
                data.Name = model.Name;
                data.AccountType = model.AccountType;
                data.OrganId = model.AccountType == InnoSoft.LS.Resources.Options.Staff ? model.OrganId : model.CustomerId;
                data.StaffId = model.AccountType == InnoSoft.LS.Resources.Options.Staff ? model.StaffId : 0;
                data.StaffName = model.AccountType == InnoSoft.LS.Resources.Options.Staff ? string.Empty : model.ContactName;

                //保存数据
                string strErrText;
                AuthenticateSystem auth = new AuthenticateSystem();
                if (auth.InsertAccount(data, LoginAccountId, LoginStaffName, out strErrText) > 0)
                {
                    return Json(string.Empty);
                }
                else
                {
                    return Json(strErrText);
                }
            }
            return View(model);
        }
Ejemplo n.º 3
0
        public ActionResult ModifyAccount(string id)
        {
            string strErrText;

            //生成Model数据
            long nAccountId = long.Parse(id);
            AuthenticateSystem auth = new AuthenticateSystem();
            Account data = auth.LoadAccount(nAccountId, LoginAccountId, LoginStaffName, out strErrText);
            if (data == null)
            {
                throw new Exception(strErrText);
            }

            AccountViewModel model = new AccountViewModel();
            model.Id = data.Id;
            model.Name = data.Name;
            model.Password = data.Password;
            model.AccountType = data.AccountType;
            model.OrganId = data.AccountType == InnoSoft.LS.Resources.Options.Staff ? data.OrganId : 0;
            model.StaffId = data.AccountType == InnoSoft.LS.Resources.Options.Staff ? data.StaffId : 0;
            model.CustomerId = data.AccountType == InnoSoft.LS.Resources.Options.Staff ? 0 : data.OrganId;
            model.ContactName = data.AccountType == InnoSoft.LS.Resources.Options.Staff ? string.Empty : data.StaffName;
            model.IsCancel = data.IsCancel;

            if (data.AccountType == InnoSoft.LS.Resources.Options.Staff)
            {
                //生成组织部门下拉列表
                OrganizationSystem organ = new OrganizationSystem();
                List<Organization> listOrganization = organ.LoadOrganizations(LoginAccountId, LoginStaffName, out strErrText);
                if (listOrganization == null)
                {
                    throw new Exception(strErrText);
                }
                List<SelectListItem> selectListOrganization = new List<SelectListItem>();
                selectListOrganization.Add(new SelectListItem { Text = string.Empty, Value = "0" });
                selectListOrganization.AddRange(from o in listOrganization
                                                orderby o.FullName
                                                select new SelectListItem
                                                {
                                                    Text = o.FullName,
                                                    Value = o.Id.ToString()
                                                });
                ViewData["Organizations"] = new SelectList(selectListOrganization, "Value", "Text", model.OrganId);

                //生成空的客户下拉列表
                List<Customer> listCustomer = new List<Customer>();
                List<SelectListItem> selectListCustomer = new List<SelectListItem>();
                selectListCustomer.Add(new SelectListItem { Text = string.Empty, Value = "0" });
                selectListCustomer.AddRange(from c in listCustomer
                                            select new SelectListItem
                                            {
                                                Text = c.Name,
                                                Value = c.Id.ToString()
                                            });
                ViewData["Customers"] = new SelectList(selectListCustomer, "Value", "Text");
            }
            else
            {
                //生成空的组织部门下拉列表
                {
                    List<Organization> listOrganization = new List<Organization>();
                    List<SelectListItem> selectListOrganization = new List<SelectListItem>();
                    selectListOrganization.Add(new SelectListItem { Text = string.Empty, Value = "0" });
                    selectListOrganization.AddRange(from o in listOrganization
                                                    select new SelectListItem
                                                    {
                                                        Text = o.FullName,
                                                        Value = o.Id.ToString()
                                                    });
                    ViewData["Organizations"] = new SelectList(selectListOrganization, "Value", "Text");
                }

                //生成客户下拉列表
                CustomerSystem customer = new CustomerSystem();
                List<Customer> listCustomer = customer.LoadCustomers(LoginAccountId, LoginStaffName, out strErrText);
                if (listCustomer == null)
                {
                    throw new Exception(strErrText);
                }
                List<SelectListItem> selectListCustomer = new List<SelectListItem>();
                selectListCustomer.Add(new SelectListItem { Text = string.Empty, Value = "0" });
                selectListCustomer.AddRange(from c in listCustomer
                                            orderby c.Name
                                            select new SelectListItem
                                            {
                                                Text = c.Name,
                                                Value = c.Id.ToString()
                                            });
                ViewData["Customers"] = new SelectList(selectListCustomer, "Value", "Text", model.OrganId);
            }

            //生成员工下拉列表
            if (data.AccountType == InnoSoft.LS.Resources.Options.Staff)
            {
                StaffSystem staff = new StaffSystem();
                List<Staff> listStaff = staff.LoadStaffsByOrganId(model.OrganId, LoginAccountId, LoginStaffName, out strErrText);
                if (listStaff == null)
                {
                    throw new Exception(strErrText);
                }
                List<SelectListItem> selectListStaff = new List<SelectListItem>();
                selectListStaff.Add(new SelectListItem { Text = string.Empty, Value = "0" });
                selectListStaff.AddRange(from s in listStaff
                                         select new SelectListItem
                                         {
                                             Text = s.FullName,
                                             Value = s.Id.ToString()
                                         });

                ViewData["Staffs"] = new SelectList(selectListStaff, "Value", "Text", model.StaffId);
            }
            else
            {
                List<Staff> listStaff = new List<Staff>();
                List<SelectListItem> selectListStaff = new List<SelectListItem>();
                selectListStaff.Add(new SelectListItem { Text = string.Empty, Value = "0" });
                selectListStaff.AddRange(from s in listStaff
                                         select new SelectListItem
                                         {
                                             Text = s.Name,
                                             Value = s.Id.ToString()
                                         });
                ViewData["Staffs"] = new SelectList(selectListStaff, "Value", "Text");
            }

            return View(model);
        }