示例#1
0
        //
        // GET: /AddUser/
        public ActionResult Index(FormCollection collection)
        {
            Dictionary<string, string> sitemaster = GetSiteMaster();
            ViewData["SiteMaster"] = sitemaster;
            if (Int32.Parse(sitemaster["isadmin"]) > 2)
            {
                if (collection.Count != 0)
                {
                    UserModel newuser = new UserModel();
                    newuser.Username = collection["UserName"];
                    newuser.Password = collection["Password"];
                    newuser.Email = "";
                    if (!MembershipService.UserIsExists(newuser.Username))
                    {
                        //创建用户
                        try
                        {
                            MembershipService.CreateNewUser(newuser);
                        }
                        catch (Exception e)
                        {
                            return View(e.Message);
                        }
                        int tempuserid = MembershipService.GetUserID(collection["UserName"]);

                        //插入企业表
                        EnterpriseMemberInfo emi = new EnterpriseMemberInfo();
                        emi.EnterPriceType = 1;
                        emi.Memberlevel = GetLevel(collection["MemberLevel"]);
                        emi.EnterpriseName = collection["EnterpriseName"];
                        emi.Telphone = collection["Telphone"];
                        emi.Contract = collection["ContractName"];
                        emi.ContractName = collection["ContractName"];
                        emi.ContractMobile = collection["Telphone"];
                        emi.Fax = "";
                        emi.Province = collection["Address"];
                        emi.Address = collection["Address"];
                        emi.Zip = "";
                        emi.CreateTime = DateTime.Now;
                        emi.CreateUserID = 4;
                        emi.SaleUserID = 4;
                        emi.ServiceUserID = 4;
                        emi.MemberCode = GetCode();
                        try
                        {
                            new EnterpriseMemberInfoDao().Insert(emi);
                        }
                        catch (Exception e)
                        {
                            return View(e.Message);
                        }
                        Hashtable htparm = new Hashtable();
                        int memberid = CRMMapper.Get().QueryForObject<int>("EnterpriseMemberInfo.myFind", collection["EnterpriseName"]);
                        //插入MemberUserInfo
                        MemberUserInfo newMember = new MemberUserInfo();
                        newMember.UserID = tempuserid;
                        newMember.MemberID = memberid;
                        newMember.Name = collection["ContractName"];
                        newMember.IsMemberAdmin = 1;
                        newMember.Mobile = collection["Telphone"];
                        newMember.Status = 1;
                        try
                        {
                            new MemberUserInfoDao().Insert(newMember);
                        }
                        catch (Exception e)
                        {
                            return View(e.Message);
                        }

                        //插入订单表
                        OrderInfo oi = new OrderInfo();
                        oi.MemberID = memberid;
                        oi.MemberUserID = tempuserid;
                        oi.ProductID = 1;
                        oi.VersionID = 1;
                        oi.ServiceStartTime = DateTime.Parse(collection["TimeFrom"]).AddHours(8);
                        oi.ServiceEndTime = DateTime.Parse(collection["TimeTo"]).AddHours(23);
                        oi.PayMethod = 1;
                        oi.OrigPrice = 0;
                        oi.PayPrice = 0;
                        oi.PayStatus = 1;
                        oi.OrderSource = 1;
                        oi.OrderStatus = 0;
                        oi.CreateTime = DateTime.Now;

                        CookieUserInfo cui = MembershipService.GetUserCookie();
                        oi.CretorUserID = CRMMapper.Get().QueryForObject<int>("EmployeeInfo.GetEmpID", cui.UserName);
                        oi.LastModifyTime = DateTime.Now;
                        oi.LastModifyUserID = 4;
                        oi.SaleUserID = 4;
                        oi.ServiceUserID = 4;

                        try
                        {
                            new OrderInfoDao().Insert(oi);
                        }
                        catch (Exception e)
                        {
                            return View(e.Message);
                        }

                        ViewData["Basicinfo"] = collection;
                        ViewData["MemberLevel"] = collection["MemberLevel"];
                        ViewData["IsExists"] = false;
                        ViewData["Success"] = true;
                    }
                    else
                    {
                        ViewData["Basicinfo"] = collection;
                        ViewData["MemberLevel"] = collection["MemberLevel"];
                        ViewData["IsExists"] = true;
                        ViewData["Success"] = false;
                    }
                }
                else
                {
                    ViewData["Success"] = false;
                    ViewData["IsExists"] = false;
                    ViewData["MemberLevel"] = "初级会员";
                }
                return View();
            }
            else
                return new RedirectResult("/Base/MemberLevelError.mvc/" + 0);
        }
        public ActionResult BasicInfo(FormCollection collection)
        {
            Dictionary<string, string> sitemaster = GetSiteMaster();
            ViewData["SiteMaster"] = sitemaster;
            int userid=Int32.Parse(CurrentUserInfo.UserID);
            //int companyID = new MemberUserInfoDao().GetMemberID(userid);
            string username=CurrentUserInfo.UserName;
            IDictionary dict = QueryBasicInfo(userid);
            if (dict != null)
            {
                string mail = MembershipService.GetUserMail(username);
                if (CurrentUserInfo != null)
                {
                    if (collection.Count == 0)
                    {
                        //ViewData["CompanyID"] = dict["MemberID"];
                        ViewData["Name"] = username;
                        dict["Email"] = mail;
                        ViewData["BasicInfo"] = dict;

                    }
                    else
                    {
                        //Dictionary<string, string> dict = new Dictionary<string, string>();
                        //dict["OldPassword"] = collection["OldPassword"];
                        //dict["NewPassword"] = collection["NewPassword"];
                        dict["ContractName"] = collection["ContractName"];
                        dict["Address"] = collection["Address"];
                        dict["Email"] = collection["Email"];
                        dict["ContractMobile"] = collection["ContractMobile"];
                        dict["Name"] = collection["Name"];
                        dict["Mobile"] = collection["Mobile"];
                        if (!MembershipService.CheckValidateCode(collection["ValidateCode"]))
                        {
                            //ViewData["CompanyID"] = companyID;
                            ViewData["Name"] = username;
                            ViewData["BasicInfo"] = dict;
                            ViewData["Validatecode"] = "False";
                            return View();
                        }
                        bool isSuccess = true;
                        EnterpriseMemberInfo upadtedEMI = new EnterpriseMemberInfo();
                        upadtedEMI = new EnterpriseMemberInfoDao().Find(Int32.Parse(dict["MemberID"].ToString()));
                        upadtedEMI.Address = collection["Address"];
                        upadtedEMI.ContractName = collection["ContractName"];
                        upadtedEMI.ContractMobile = collection["ContractMobile"];
                        MemberUserInfo mui = new MemberUserInfo();
                        Hashtable ht = new Hashtable();
                        ht["Mobile"] = collection["Mobile"];
                        ht["Name"] = collection["Name"];
                        ht["Userid"] = userid;
                        try
                        {
                            new EnterpriseMemberInfoDao().Update(upadtedEMI);
                            MembershipService.UpdateMail(userid, collection["Email"]);
                            CRMMapper.Get().Update("MemberUserInfo.myupdate", ht);
                        }
                        catch (Exception)
                        {
                            isSuccess = false;
                        }
                        //ViewData["CompanyID"] = companyID;
                        ViewData["Name"] = username;
                        ViewData["Basicinfo"] = dict;
                        ViewData["Success"] = isSuccess;
                    }
                }
            }
            else
            {
                UserModel um = new MembershipUserService().GetUserName(userid);
                IDictionary dictex = new Dictionary<string, string>();
                if (collection.Count == 0)
                {
                    dictex.Add("Address", um.Address);
                    dictex.Add("ContractMobile", um.Mobile);
                    dictex.Add("Mobile", um.Mobile);
                    dictex.Add("Email", um.Email);
                    ViewData["Name"] = username;
                    ViewData["BasicInfo"] = dictex;
                }
                else
                {
                    dictex.Add("Address", collection["Address"]);
                    dictex.Add("ContractMobile", collection["ContractMobile"]);
                    dictex.Add("Mobile", collection["Mobile"]);
                    dictex.Add("Email", collection["Email"]);
                    ViewData["Name"] = username;
                    ViewData["BasicInfo"] = dictex;
                    if (!MembershipService.CheckValidateCode(collection["ValidateCode"]))
                    {
                        //ViewData["CompanyID"] = companyID;
                        ViewData["Validatecode"] = "False";
                        return View();
                    }
                    bool isSuccess = true;
                    Hashtable ht = new Hashtable();
                    ht["Mobile"] = collection["Mobile"];
                    ht["Name"] = collection["Name"];
                    ht["Address"] = collection["Address"];
                    ht["Email"] = collection["Email"];
                    ht["Userid"] = userid;
                    try
                    {
                        MembershipService.UpdateBaseInfo(ht);
                    }
                    catch (Exception)
                    {
                        isSuccess = false;
                    }
                    //ViewData["CompanyID"] = companyID;
                    ViewData["Success"] = isSuccess;
                }
            }
            ViewData["titlename"] = "基本资料修改";
            return View();
        }