Exemplo n.º 1
0
        /// <summary>
        /// 单个保存
        /// </summary>
        /// <returns></returns>
        public ActionResult Save()
        {
            var    yybh = GLYadmin.YYID;
            string pqbh = Request["pqbh"];
            string qybh = Request["qybh"];

            //日期
            DateTime rq = Convert.ToDateTime(Request["tjrq"]);

            //时间段
            var kssjList = Request.Params.GetValues("kssj");
            var jssjList = Request.Params.GetValues("jssj");
            var tjrsList = Request.Params.GetValues("tjrs");


            List <PqTjsjModel> tjsjList = new List <PqTjsjModel>();

            for (int i = 0; i < kssjList.Count(); i++)
            {
                if (string.IsNullOrEmpty(kssjList[i]) || string.IsNullOrEmpty(jssjList[i]))
                {
                    return(Json(new { code = 500, msg = "时间段不能为空" }));
                }
                else if (string.IsNullOrEmpty(tjrsList[i]))
                {
                    return(Json(new { code = 500, msg = "预留人数不能为空" }));
                }
                for (int j = i + 1; j < kssjList.Count(); j++)
                {
                    if (Convert.ToDateTime(kssjList[j]) > Convert.ToDateTime(kssjList[i]) && Convert.ToDateTime(kssjList[j]) < Convert.ToDateTime(jssjList[i]))
                    {
                        return(Json(new { code = 500, msg = "第" + (i + 1) + "和第" + (j + 1) + "行时间有重叠" }));
                    }
                    else if (Convert.ToDateTime(jssjList[j]) > Convert.ToDateTime(kssjList[i]) && Convert.ToDateTime(jssjList[j]) < Convert.ToDateTime(jssjList[i]))
                    {
                        return(Json(new { code = 500, msg = "第" + (i + 1) + "和第" + (j + 1) + "行时间有重叠" }));
                    }
                    else if (Convert.ToDateTime(kssjList[j]) < Convert.ToDateTime(kssjList[i]) && Convert.ToDateTime(jssjList[j]) > Convert.ToDateTime(jssjList[i]))
                    {
                        return(Json(new { code = 500, msg = "第" + (i + 1) + "和第" + (j + 1) + "行时间有重叠" }));
                    }
                }
                var kssj = Convert.ToDateTime(rq.ToString("yyyy-MM-dd") + " " + kssjList[i]);
                var jssj = Convert.ToDateTime(rq.ToString("yyyy-MM-dd") + " " + jssjList[i]);
                tjsjList.Add(new PqTjsjModel {
                    pqbh = pqbh, yybh = yybh, qybh = qybh, rq = rq, kssj = kssj, jssj = jssj, tjrs = Convert.ToInt32(tjrsList[i])
                });
            }
            PqTjrqModel tjrqModel = new PqTjrqModel {
                pqbh = pqbh, yybh = yybh, qybh = qybh, rq = rq, flag = 0, tjrs = tjrsList.Sum(x => Convert.ToInt32(x))
            };

            pqtjsjService.Save(tjrqModel, tjsjList);
            return(Json(new { code = 200, msg = "" }));
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        public void Update(PqTjrqModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update pq_tjrq set ");
            strSql.Append("yybh=@yybh,");
            strSql.Append("qybh=@qybh,");
            strSql.Append("rq=@rq,");
            strSql.Append("tjrs=@tjrs,");
            strSql.Append("flag=@flag");
            strSql.Append(" where id=@id");
            using (IDbConnection conn = new DapperConnection().DbConnection)
            {
                conn.Execute(strSql.ToString(), model);
            }
        }
        public void Save(PqTjrqModel model, List <PqTjsjModel> list)
        {
            StringBuilder strSql = new StringBuilder();

            using (IDbConnection conn = new DapperConnection().DbConnection)
            {
                IDbTransaction transaction = conn.BeginTransaction();
                try
                {
                    strSql.AppendLine("IF EXISTS(SELECT 1 FROM dbo.pq_tjrq WHERE qybh=@qybh AND rq=@rq)");
                    strSql.AppendLine("BEGIN");
                    strSql.AppendLine("update pq_tjrq SET flag=0,tjrs=@tjrs WHERE qybh=@qybh AND rq=@rq");
                    strSql.AppendLine("END");
                    strSql.AppendLine("ELSE ");
                    strSql.AppendLine("BEGIN");
                    strSql.AppendLine("insert into pq_tjrq(yybh,qybh,rq,tjrs,flag)values (@yybh,@qybh,@rq,@tjrs,0)");
                    strSql.AppendLine("END");
                    conn.Execute(strSql.ToString(), model, transaction);


                    strSql.Clear();
                    strSql.Append("DELETE FROM dbo.pq_tjsj WHERE qybh=@qybh AND rq=@rq ");
                    conn.Execute(strSql.ToString(), new { qybh = model.qybh, rq = model.rq }, transaction);
                    strSql.Clear();

                    foreach (var item in list)
                    {
                        strSql.Append("insert into pq_tjsj(");
                        strSql.Append("yybh,qybh,rq,kssj,jssj,tjrs,pqbh)");
                        strSql.Append(" values (");
                        strSql.Append("@yybh,@qybh,@rq,@kssj,@jssj,@tjrs,@pqbh)");
                        conn.Execute(strSql.ToString(), item, transaction);
                        strSql.Clear();
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }
Exemplo n.º 4
0
        public ActionResult ChangeFlag(string qybh, DateTime rq, int flag)
        {
            var yybh  = GLYadmin.YYID;
            var model = tjrqService.GetModel(qybh, rq);

            if (model == null)
            {
                model = new PqTjrqModel
                {
                    rq   = rq,
                    flag = flag,
                    yybh = yybh,
                    qybh = qybh,
                    tjrs = 0
                };
                tjrqService.Add(model);
            }
            else
            {
                model.flag = flag;
                tjrqService.Update(model);
            }
            return(Json(new { code = 200, msg = "" }));
        }
        /// <summary>
        /// 追加保存
        /// </summary>
        /// <param name="model"></param>
        public void ZjSave(PqQyszModel model)
        {
            using (IDbConnection conn = new DapperConnection().DbConnection)
            {
                IDbTransaction transaction = conn.BeginTransaction();
                try
                {
                    StringBuilder strSql = new StringBuilder();

                    strSql.Append("UPDATE dbo.pq_qysz SET jsrq=@jsrq WHERE pqbh=@pqbh");

                    conn.Execute(strSql.ToString(), model, transaction);
                    strSql.Clear();


                    model.SjdList = JsonConvert.DeserializeObject <List <Sjd> >(model.sjd);


                    for (int i = 0; i < model.jsrq.Subtract(model.ksrq).TotalDays + 1; i++)
                    {
                        DateTime rq = model.ksrq.AddDays(i);

                        PqTjrqModel rqModel = new PqTjrqModel();
                        rqModel.pqbh = model.pqbh;
                        rqModel.qybh = model.qybh;
                        rqModel.rq   = model.ksrq.AddDays(i);
                        rqModel.tjrs = model.SjdList.Sum(x => x.tjrs);
                        rqModel.yybh = model.yybh;
                        rqModel.flag = GetFlag(model.ksrq.AddDays(i), model.xxr);

                        strSql.Append("insert into pq_tjrq(");
                        strSql.Append("pqbh,yybh,qybh,rq,tjrs,flag)");
                        strSql.Append(" values (");
                        strSql.Append("@pqbh,@yybh,@qybh,@rq,@tjrs,@flag)");
                        conn.Execute(strSql.ToString(), rqModel, transaction);
                        strSql.Clear();

                        foreach (var item in model.SjdList)
                        {
                            PqTjsjModel sjModel = new PqTjsjModel();
                            sjModel.yybh = model.yybh;
                            sjModel.pqbh = model.pqbh;
                            sjModel.qybh = model.qybh;
                            sjModel.rq   = rqModel.rq;
                            sjModel.tjrs = item.tjrs;
                            sjModel.kssj = Convert.ToDateTime(rqModel.rq.ToString("yyyy-MM-dd") + " " + item.kssj);
                            sjModel.jssj = Convert.ToDateTime(rqModel.rq.ToString("yyyy-MM-dd") + " " + item.jssj);
                            strSql.Append("insert into pq_tjsj(");
                            strSql.Append("pqbh,yybh,qybh,rq,kssj,jssj,tjrs)");
                            strSql.Append(" values (");
                            strSql.Append("@pqbh,@yybh,@qybh,@rq,@kssj,@jssj,@tjrs)");
                            conn.Execute(strSql.ToString(), sjModel, transaction);
                            strSql.Clear();
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pjtc"></param>
        /// <param name="pjtcrs"></param>
        public void Save(PqQyszModel model, string[] pjtc, string[] pjtcrs, string[] pjtcXxr, string[] pjtcSfxz)
        {
            using (IDbConnection conn = new DapperConnection().DbConnection)
            {
                IDbTransaction transaction = conn.BeginTransaction();
                try
                {
                    StringBuilder strSql = new StringBuilder();
                    if (!string.IsNullOrEmpty(model.pqbh))
                    {
                        strSql.Append("DELETE FROM dbo.pq_tjrq WHERE pqbh=@pqbh;");
                        strSql.Append("DELETE FROM dbo.pq_tjsj WHERE pqbh=@pqbh;");
                        strSql.Append("DELETE FROM dbo.pq_pjtc WHERE pqbh=@pqbh;");
                        strSql.Append("DELETE FROM dbo.pq_pjtcgz WHERE pqbh=@pqbh;");
                        strSql.Append("UPDATE dbo.pq_qysz SET ksrq=@ksrq,jsrq=@jsrq,jzsj=@jzsj,xxr=@xxr,tqts=@tqts,sjd=@sjd,tjrs=@tjrs,tjrs_dy=@tjrs_dy WHERE pqbh=@pqbh");
                    }
                    else
                    {
                        model.pqbh = GetPqbh();
                        strSql.Append("insert into pq_qysz(pqbh,yybh,qybh,ksrq,jsrq,cjsj,jzsj,xxr,tqts,sjd,tjrs,tjrs_dy) values (@pqbh,@yybh,@qybh,@ksrq,@jsrq,@cjsj,@jzsj,@xxr,@tqts,@sjd,@tjrs,@tjrs_dy);");
                    }
                    conn.Execute(strSql.ToString(), model, transaction);
                    strSql.Clear();


                    //foreach (var item in pjtcList)
                    //{
                    //    strSql.Append("insert into pq_pjtc(");
                    //    strSql.Append("pqbh,tcbh,tjrs)");
                    //    strSql.Append(" values (");
                    //    strSql.Append("@pqbh,@tcbh,@tjrs)");
                    //    item.pqbh = model.pqbh;
                    //    conn.Execute(strSql.ToString(), item, transaction);
                    //    strSql.Clear();
                    //}

                    if (pjtc != null && pjtcrs != null)
                    {
                        for (int i = 0; i < pjtc.Length; i++)
                        {
                            var fzbh = GetFzbh();
                            var tjrs = Convert.ToInt32(pjtcrs[i]);
                            var xxr  = pjtcXxr[i];
                            var sfxz = Convert.ToInt32(pjtcSfxz[i]);

                            strSql.Append("insert into pq_pjtcgz(");
                            strSql.Append("pqbh,fzbh,tjrs,xxr,sfxz)");
                            strSql.Append(" values (");
                            strSql.Append("@pqbh,@fzbh,@tjrs,@xxr,@sfxz)");
                            conn.Execute(strSql.ToString(), new { pqbh = model.pqbh, fzbh = fzbh, tjrs = tjrs, xxr = xxr, sfxz = sfxz }, transaction);
                            strSql.Clear();
                            foreach (var item in pjtc[i].Split(','))
                            {
                                strSql.Append("insert into pq_pjtc(");
                                strSql.Append("pqbh,tcbh,fzbh)");
                                strSql.Append(" values (");
                                strSql.Append("@pqbh,@tcbh,@fzbh)");
                                conn.Execute(strSql.ToString(), new { pqbh = model.pqbh, fzbh = fzbh, tcbh = item }, transaction);
                                strSql.Clear();
                            }
                        }
                    }


                    for (int i = 0; i < model.jsrq.Subtract(model.ksrq).TotalDays + 1; i++)
                    {
                        DateTime rq = model.ksrq.AddDays(i);

                        PqTjrqModel rqModel = new PqTjrqModel();
                        rqModel.pqbh = model.pqbh;
                        rqModel.qybh = model.qybh;
                        rqModel.rq   = model.ksrq.AddDays(i);
                        rqModel.tjrs = model.SjdList.Sum(x => x.tjrs);
                        rqModel.yybh = model.yybh;
                        rqModel.flag = GetFlag(model.ksrq.AddDays(i), model.xxr);

                        strSql.Append("insert into pq_tjrq(");
                        strSql.Append("pqbh,yybh,qybh,rq,tjrs,flag)");
                        strSql.Append(" values (");
                        strSql.Append("@pqbh,@yybh,@qybh,@rq,@tjrs,@flag)");
                        conn.Execute(strSql.ToString(), rqModel, transaction);
                        strSql.Clear();

                        foreach (var item in model.SjdList)
                        {
                            PqTjsjModel sjModel = new PqTjsjModel();
                            sjModel.yybh = model.yybh;
                            sjModel.pqbh = model.pqbh;
                            sjModel.qybh = model.qybh;
                            sjModel.rq   = rqModel.rq;
                            sjModel.tjrs = item.tjrs;
                            sjModel.kssj = Convert.ToDateTime(rqModel.rq.ToString("yyyy-MM-dd") + " " + item.kssj);
                            sjModel.jssj = Convert.ToDateTime(rqModel.rq.ToString("yyyy-MM-dd") + " " + item.jssj);
                            strSql.Append("insert into pq_tjsj(");
                            strSql.Append("pqbh,yybh,qybh,rq,kssj,jssj,tjrs)");
                            strSql.Append(" values (");
                            strSql.Append("@pqbh,@yybh,@qybh,@rq,@kssj,@jssj,@tjrs)");
                            conn.Execute(strSql.ToString(), sjModel, transaction);
                            strSql.Clear();
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }