Example #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (isModify)
            {
                int quantity = 0;
                if (!string.IsNullOrEmpty(txtQuantity.Text))
                {
                    quantity = Convert.ToInt32(txtQuantity.Text);
                }
                //using (TransactionScope transaction = new TransactionScope())
                //{
                //DXInfo.Models.OrderBooks orderBook = uow.OrderBooks.GetById(g=>g.Id==this.orderBook.Id);//.Where(w => w.Id == this.orderBook.Id).FirstOrDefault();
                if (orderBook != null)
                {
                    DXInfo.Principal.MyPrincipal mp = Thread.CurrentPrincipal as DXInfo.Principal.MyPrincipal;
                    DXInfo.Principal.MyIdentity  mi = mp.Identity as DXInfo.Principal.MyIdentity;
                    orderBook.CreateDate    = DateTime.Now;
                    orderBook.DeptId        = mi.dept.DeptId;
                    orderBook.UserId        = mi.user.UserId;
                    orderBook.Quantity      = quantity;
                    orderBook.Customer      = txtLinkName.Text;
                    orderBook.LinkPhone     = txtLinkPhone.Text;
                    orderBook.BookBeginDate = Convert.ToDateTime(dpBeginDate.Text + " " + tpBeginTime.Value.GetValueOrDefault().Hour + ":" + tpBeginTime.Value.GetValueOrDefault().Minute);
                    orderBook.BookEndDate   = Convert.ToDateTime(dpEndDate.Text + " " + tpEndTime.Value.GetValueOrDefault().Hour + ":" + tpEndTime.Value.GetValueOrDefault().Minute);
                    orderBook.Status        = 0;
                    uow.OrderBooks.Update(orderBook);

                    DXInfo.Models.OrderBooksHis orderBookHis = new DXInfo.Models.OrderBooksHis();
                    orderBookHis.LinkId        = orderBook.Id;
                    orderBookHis.CreateDate    = DateTime.Now;
                    orderBookHis.DeptId        = mi.dept.DeptId;
                    orderBookHis.UserId        = mi.user.UserId;
                    orderBookHis.Quantity      = orderBook.Quantity;
                    orderBookHis.Customer      = orderBook.Customer;
                    orderBookHis.LinkPhone     = orderBook.LinkPhone;
                    orderBookHis.BookBeginDate = orderBook.BookBeginDate;
                    orderBookHis.BookEndDate   = orderBook.BookEndDate;
                    orderBookHis.Status        = orderBook.Status;
                    uow.OrderBooksHis.Add(orderBookHis);

                    uow.Commit();

                    //transaction.Complete();
                    //}
                }
                this.DialogResult = true;
                this.Close();
            }
            else
            {
                this.DialogResult = true;
                this.Close();
            }
        }
Example #2
0
        private void login()
        {
            string userName = this.UserName;
            string passwd   = this.Password;

            if (string.IsNullOrWhiteSpace(userName))
            {
                MessageBox.Show("请输入用户名");
                return;
            }
            if (string.IsNullOrWhiteSpace(passwd))
            {
                MessageBox.Show("请输入密码");
                return;
            }
            if (!Membership.ValidateUser(userName, passwd))
            {
                MessageBox.Show("用户名或密码错误,多次错误后此用户将被锁定");
                return;
            }
            MembershipUser user = Membership.GetUser(userName);

            if (user == null)
            {
                throw new ArgumentException("操作员信息错误");
            }
            Guid userId = Guid.Parse(user.ProviderUserKey.ToString());

            DXInfo.Models.aspnet_CustomProfile oper = Uow.aspnet_CustomProfile.GetById(g => g.UserId == userId);
            if (oper == null)
            {
                throw new ArgumentException("操作员信息错误");
            }

            DXInfo.Models.aspnet_Users auser = Uow.aspnet_Users.GetById(g => g.UserId == userId);

            var nc = Uow.NameCode.GetAll().Where(w => w.Type == "LocalDept").FirstOrDefault();

            if (nc == null)
            {
                MessageBox.Show("请首先设置本地门店", "设置本地门店", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (string.IsNullOrEmpty(nc.Value))
            {
                MessageBox.Show("本地门店信息错误", "设置本地门店", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            Guid deptId = Guid.Parse(nc.Value);

            if (!oper.DeptId.HasValue)
            {
                MessageBox.Show("请设置操作员门店信息");
                return;
            }
            if (oper.DeptId.Value != deptId && userName != "admin")
            {
                MessageBox.Show("不是这个门店操作员,不能登录");
                return;
            }
            DXInfo.Models.Depts dept = Uow.Depts.GetById(g => g.DeptId == deptId);
            if (dept == null)
            {
                throw new ArgumentException("门店信息错误");
            }

            DXInfo.Principal.MyIdentity mi = new DXInfo.Principal.MyIdentity(oper, auser, dept, "MyIdentity");

            List <DXInfo.Models.aspnet_Sitemaps> lFunc = GetAllSitemapKeys(oper.UserId, auser.UserName);

            DXInfo.Principal.MyPrincipal mp = new DXInfo.Principal.MyPrincipal(mi, lFunc);

            if (Thread.CurrentPrincipal == null)
            {
                AppDomain.CurrentDomain.SetThreadPrincipal(mp);
            }
            else
            {
                Thread.CurrentPrincipal = mp;
            }
            //Uow.Dispose();
            this.UserName = null;
            this.Password = null;
            var rmw = ServiceLocator.Current.GetInstance <RibbonMainWindow>();

            App.Current.MainWindow = rmw;
            rmw.Show();
            Messenger.Default.Send(new CloseViewMessageToken());
        }