예제 #1
0
        /// <summary>
        /// 根据单据类型编号,生成单号
        /// </summary>
        /// <param name="BillTypeNumber">单据类型编号,连接字符串</param>
        /// <returns>单号</returns>
        public static string GenerateBillNumber(string BillTypeNumber,string connString)
        {
            BonsaiiDbContext db = new BonsaiiDbContext(connString);
            BillPropertyModels tmp = db.BillProperties.Where(p => p.Type == BillTypeNumber).Single();
            string date = DateTime.Now.ToString("yyyyMMdd");
            //为流水号补充零
            string SerialNumber = AddZero(tmp.Count, tmp.SerialNumber);
            //更新单号的计数值
            tmp.Count++;
            db.Entry(tmp).State = EntityState.Modified;
            db.SaveChanges();

            switch (tmp.CodeMethod)
            {
                case CodeMethod.One:
                    return DateTime.Now.ToString("yyyyMMdd").ToString() + SerialNumber;
                case CodeMethod.Two:
                    return DateTime.Now.ToString("yyyyMM").ToString() + SerialNumber;
                case CodeMethod.Three:
                    return tmp.Code.Substring(0, 10 - tmp.SerialNumber) + SerialNumber;
                default:
                    return "";
            }
        }
예제 #2
0
        /// <summary>
        /// 这个函数的调用顺序在:BaseController的构造函数和继承BaseController的构造函数调用之后才进行调用
        /// </summary>
        /// <param name="requestContext"></param>
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
               //     UserData = Session["UserData"] as SessionData;

            if (Session["UserName"] != null)
            {
                this.UserName = Session["UserName"] as string;
                this.CompanyId = Session["CompanyId"] as string;
                this.ConnectionString = Session["ConnectionString"] as string;
                this.CompanyFullName = Session["CompanyFullName"] as string;
                this.IsProved = (bool)Session["IsProved"];
            }
            else
            {
                UserManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
                var user = UserManager.FindById(User.Identity.GetUserId());

                //既没有通过系统登录,也没有通过外部登录,跳转到登录页面
                if (user == null)
                    Rederect(requestContext, Url.Action("Login", "Account"));
                //通过外部登录或者浏览器保存的cookie和session信息自动进行了登录
                this.UserName = user.UserName;
                this.CompanyId = user.CompanyId;
                this.ConnectionString = user.ConnectionString;
                this.CompanyFullName = user.CompanyFullName;
                this.IsProved = user.IsProved;

                Session["UserName"] = this.UserName;
                Session["CompanyId"] = this.CompanyId;
                Session["ConnectionString"] = this.ConnectionString;
                Session["CompanyFullName"] = this.CompanyFullName;
                Session["IsProved"] = this.IsProved;
            }
            db = new BonsaiiDbContext(this.ConnectionString);
        }