public void add(TeacherDayCheckRecordModel teacherdaycheckrecord)
        {
            SqlConnection cn = null;
            SqlTransaction tc = null;
            try
            {
                cn = DbHelperSQL.getConnection();
                tc = DbHelperSQL.startTransaction(cn);

                IList<QueryModel> qmList = new List<QueryModel>();
                qmList.Add(MakeUtil.getQueryModel("SchoolNo", "'", SqlWhere.WhereOperator.Equal, teacherdaycheckrecord.SchoolNo));
                qmList.Add(MakeUtil.getQueryModel("D_Name", "'", SqlWhere.WhereOperator.Equal, teacherdaycheckrecord.D_Name));
                qmList.Add(MakeUtil.getQueryModel("DS_JID", "'", SqlWhere.WhereOperator.Equal, teacherdaycheckrecord.DS_JID));
                qmList.Add(MakeUtil.getQueryModel("DS_Name", "'", SqlWhere.WhereOperator.Equal, teacherdaycheckrecord.DS_Name));
                qmList.Add(MakeUtil.getQueryModel("1", "", SqlWhere.WhereOperator.Equal, "1 AND DateDiff(dd, HappenDate,getdate())=0"));
                var oldList = teacherdaycheckrecordDal.getModelList(cn, tc, qmList, -1);
                if (oldList.Any())
                {
                    teacherdaycheckrecord.Evenid = oldList[0].Evenid;
                    teacherdaycheckrecordDal.update(cn, tc, teacherdaycheckrecord);
                }
                else
                {
                    //执行新增写进数据库
                    teacherdaycheckrecordDal.add(cn, tc, teacherdaycheckrecord);
                }

                DbHelperSQL.commitTransaction(tc);
            }
            catch (Exception dalEx)
            {
                DbHelperSQL.rollBackTransaction(tc);
                throw new MakeException(ExpSort.数据库, dalEx.Message);
            }
            finally
            {
                DbHelperSQL.closeConnection(cn);
            }
        }
 public bool update(SqlConnection cn, SqlTransaction tc, TeacherDayCheckRecordModel model)
 {
     return DbHelperSQL.updateModel<TeacherDayCheckRecordModel>(model, "TeacherDayCheckRecord", "Evenid", model.Evenid.ToString(), "'", cn, tc);
 }
 public bool add(SqlConnection cn, SqlTransaction tc, TeacherDayCheckRecordModel model)
 {
     return DbHelperSQL.insertModel<TeacherDayCheckRecordModel>(model, "TeacherDayCheckRecord", cn, tc);
 }
    protected void AgreeSubmitClick(object sender, EventArgs e)
    {
        if (StudentLeaveRecordModel.RecordState != 0)
        {
            Response.Redirect("SchoolChose.aspx");
        }
        //不作时间限制
        //        if (StudentLeaveRecordModel.HappenDate.ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd"))
        //        {
        //            Script.alertMsg("", Page);
        //            return;
        //        }
        var model = StudentLeaveRecordModel;
        //同意
        model.RecordState = 1;
        //添加一个教师晨报的记录
        var teacherDayCheckRecordModel = new TeacherDayCheckRecordModel
        {
            DS_JID = model.Student_JID,
            DS_Name = model.Student_Name,
            D_Name = model.Student_DName,
            LeaveType = model.LeaveType,
            Memos = model.Memos,
            SchoolNo = model.SchoolNo,
            HappenDate = model.TimeSelect
        };

        SqlConnection cn = null;
        SqlTransaction tc = null;
        try
        {
            cn = DbHelperSQL.getConnection();
            tc = DbHelperSQL.startTransaction(cn);

            //
            _studentLeaveRecordDal.update(cn, tc, model);

            IList<QueryModel> qmList = new List<QueryModel>();
            qmList.Add(MakeUtil.getQueryModel("SchoolNo", "'", SqlWhere.WhereOperator.Equal, teacherDayCheckRecordModel.SchoolNo));
            var sdmodel = _schoolDataDal.getModel(cn, tc, qmList);
            if (sdmodel.Evenid <= 0)
            {
                throw new Exception("找不到相关的学校的资料,请重新登录");
            }

            qmList.Clear();
            qmList.Add(MakeUtil.getQueryModel("SchoolNo", "'", SqlWhere.WhereOperator.Equal, teacherDayCheckRecordModel.SchoolNo));
            qmList.Add(MakeUtil.getQueryModel("D_Name", "'", SqlWhere.WhereOperator.Equal, teacherDayCheckRecordModel.D_Name));
            qmList.Add(MakeUtil.getQueryModel("DS_JID", "'", SqlWhere.WhereOperator.Equal, teacherDayCheckRecordModel.DS_JID));
            qmList.Add(MakeUtil.getQueryModel("DS_Name", "'", SqlWhere.WhereOperator.Equal, teacherDayCheckRecordModel.DS_Name));
            qmList.Add(MakeUtil.getQueryModel("HappenDate", "", SqlWhere.WhereOperator.BiggerEqual, teacherDayCheckRecordModel.HappenDate.ToString("yyyy-MM-dd")));
            qmList.Add(MakeUtil.getQueryModel("HappenDate", "", SqlWhere.WhereOperator.Smaller, teacherDayCheckRecordModel.HappenDate.AddDays(1).ToString("yyyy-MM-dd")));
            var oldList = _teacherdaycheckrecordDal.getModelList(cn, tc, qmList, -1);
            if (oldList.Any())
            {
                teacherDayCheckRecordModel.Evenid = oldList[0].Evenid;
                _teacherdaycheckrecordDal.update(cn, tc, teacherDayCheckRecordModel);
            }
            else
            {
                //执行新增写进数据库
                _teacherdaycheckrecordDal.add(cn, tc, teacherDayCheckRecordModel);
            }

        //            qmList.Clear();
        //            qmList.Add(MakeUtil.getQueryModel("SchoolNo", "'", SqlWhere.WhereOperator.Equal, teacherDayCheckRecordModel.SchoolNo));
        //            qmList.Add(MakeUtil.getQueryModel("D_Name", "'", SqlWhere.WhereOperator.Equal, teacherDayCheckRecordModel.D_Name));
        //            qmList.Add(MakeUtil.getQueryModel("1", "", SqlWhere.WhereOperator.Equal, "1 AND DateDiff(dd, HappenDate,getdate())=0"));
        //            if (!_teacherDayCheckSubmitRecordDal.getModelList(cn, tc, qmList, -1).Any())
        //            {
        //                var teacherdaychecksubmitrecord = new TeacherDayCheckSubmitRecordModel
        //                {
        //                    D_Name = teacherDayCheckRecordModel.D_Name,
        //                    SchoolNo = teacherDayCheckRecordModel.SchoolNo,
        //                    IsSubmit = true
        //                };
        //
        //                //执行新增写进数据库
        //                _teacherDayCheckSubmitRecordDal.add(cn, tc, teacherdaychecksubmitrecord);
        //            }

            //发送同意微信到家长的微信
            var rs = Helper.WxSendStudentLeaveConfirmText("同意", model.Student_Name, model.Teacher_Name, sdmodel.SchoolName,
                model.Student_Openid, Helper.GetWxPublicPlatformModel());
            if (rs == "SUCCESS")
            {
                //
                Script.alertMsg("完成", Page);
                Script.scriptRedirect("SchoolChose.aspx", Page);
            }
            else
            {
                throw new Exception("发生错误,错误信息为" + rs + ",请重新审核");
            }

            DbHelperSQL.commitTransaction(tc);
        }
        catch (Exception dalEx)
        {
            DbHelperSQL.rollBackTransaction(tc);
            Script.alertMsg(dalEx.Message, Page);
        }
        finally
        {
            DbHelperSQL.closeConnection(cn);
        }
    }
        public void update(TeacherDayCheckRecordModel teacherdaycheckrecord)
        {
            SqlConnection cn = null;
            SqlTransaction tc = null;
            try
            {
                cn = DbHelperSQL.getConnection();
                tc = DbHelperSQL.startTransaction(cn);

            teacherdaycheckrecordDal.update(cn, tc, teacherdaycheckrecord);

                DbHelperSQL.commitTransaction(tc);
            }
            catch (Exception dalEx)
            {
                DbHelperSQL.rollBackTransaction(tc);
                throw new MakeException(ExpSort.数据库, dalEx.Message);
            }
            finally
            {
                DbHelperSQL.closeConnection(cn);
            }
        }