private void Create()
        {
            string  Year       = Request["Year"];
            string  Month      = Request["Month"];
            string  day        = Request["day"];
            string  SignType   = Request["SignType"];
            string  ProjectId  = Request["ProjectId"];
            string  UserId     = Request["UserId"];
            string  UserName   = Request["UserName"];
            string  Attachment = Request["Attachment"];
            string  Remark     = Request["Remark"];
            string  Id         = Request["Id"];
            Project ProEnt     = Project.Find(ProjectId);

            //查询是否存在该项目该年此月份的考勤
            sql = @"select * from NCRL_SP..ProjectAttendance where Year='" + Convert.ToInt32(Year) + "' and Month='" + Convert.ToInt32(Month) + "' and ProjectId='" + ProjectId + "'";
            DataTable dt = DataHelper.QueryDataTable(sql);

            //查询是否存在该部门本该年此月份的考勤
            sql = @"select Id from NCRL_SP..DeptAttendance where Year='" + Convert.ToInt32(Year) + "'and Month='" + Convert.ToInt32(Month) + "' and BelongDeptId ='" + ProEnt.BelongDeptId + "'";
            DataTable da = DataHelper.QueryDataTable(sql);

            //查询本公司是否存在该年此月份的考勤
            sql = @"select  * from NCRL_SP..CmpAttendance where Year='" + Convert.ToInt32(Year) + "'and Month='" + Convert.ToInt32(Month) + "'";
            DataTable ca = DataHelper.QueryDataTable(sql);

            if (string.IsNullOrEmpty(Id))
            {
                if (dt.Rows.Count > 0)
                {
                    return;
                }
                Pent                = new ProjectAttendance();
                Pent.Attachment     = Attachment;
                Pent.Remark         = Remark;
                Pent.ProjectId      = ProjectId;
                Pent.ProjectName    = ProEnt.ProjectName;
                Pent.Year           = Convert.ToInt32(Year);
                Pent.Month          = Convert.ToInt32(Month);
                Pent.PManagerId     = ProEnt.PManagerId;
                Pent.PManagerName   = ProEnt.PManagerName;
                Pent.BelongDeptId   = ProEnt.BelongDeptId;
                Pent.BelongDeptName = ProEnt.BelongDeptName;
                Pent.CreateId       = WebPortalService.CurrentUserInfo.UserID;
                Pent.CreateName     = WebPortalService.CurrentUserInfo.Name;
                Pent.CreateTime     = DateTime.Now;
                Pent.DoCreate();
                if (da.Rows.Count <= 0)
                {
                    dent                = new DeptAttendance();
                    dent.Year           = Convert.ToInt32(Year);
                    dent.Month          = Convert.ToInt32(Month);
                    dent.BelongDeptId   = Pent.BelongDeptId;
                    dent.BelongDeptName = Pent.BelongDeptName;
                    dent.DoCreate();
                }
                if (ca.Rows.Count <= 0)
                {
                    cent       = new CmpAttendance();
                    cent.Year  = Convert.ToInt32(Year);
                    cent.Month = Convert.ToInt32(Month);
                    cent.DoCreate();
                }
            }
            else
            {
                Pent = ProjectAttendance.Find(Id);
                if (Pent.Attachment != Attachment || Pent.Remark != Remark)
                {
                    Pent.Attachment = Attachment;
                    Pent.Remark     = Remark;
                    Pent.DoUpdate();
                }
            }

            sql = "select * from NCRL_SP..ProjectAttendanceDetail where UserId='" + UserId + "'and CONVERT(varchar(10), AttendanceDate,120)='" + Convert.ToDateTime(Year + "-" + Month + "-" + day).ToString("yyyy-MM-dd") + "' and ProjectAttendanceId<>'" + Id + "' or ProjectAttendanceId is null ";
            IList <EasyDictionary> dicss = DataHelper.QueryDictList(sql);

            if (dicss.Count > 0)
            {
                ents = ProjectAttendanceDetail.Find(dicss[0].Get <string>("Id"));
                ents.AttendanceType = SignType;
                if (!string.IsNullOrEmpty(Id))
                {
                    ents.ProjectAttendanceId = Id;
                }
                else
                {
                    ents.ProjectAttendanceId = Pent.Id;
                }
                ents.Description = "";
                ents.DoUpdate();

                if (!string.IsNullOrEmpty(Id))
                {
                    Response.Write("{success:  true  ,id:'" + Id + "'}");
                    Response.End();
                    return;
                }
                Response.Write("{success:  true  ,id:'" + Pent.Id + "'}");
                Response.End();
                return;
            }

            sql   = "select * from NCRL_SP..ProjectAttendanceDetail where UserId='" + UserId + "'and CONVERT(varchar(10), AttendanceDate,120)='" + Convert.ToDateTime(Year + "-" + Month + "-" + day).ToString("yyyy-MM-dd") + "' and ProjectAttendanceId='" + Id + "'";
            dicss = DataHelper.QueryDictList(sql);
            if (dicss.Count > 0)
            {
                ents = ProjectAttendanceDetail.Find(dicss[0].Get <string>("Id"));
                if (ents.AttendanceType != SignType)
                {
                    ents.AttendanceType = SignType;
                }
                else
                {
                    sql = "delete NCRL_SP..ProjectAttendanceDetail where  UserId='" + UserId + "'and CONVERT(varchar(10), AttendanceDate,120)='" + Convert.ToDateTime(Year + "-" + Month + "-" + day).ToString("yyyy-MM-dd") + "' and ProjectAttendanceId='" + Id + "'";
                    DataHelper.ExecSql(sql);
                    Response.Write("{success:  true  ,id:'" + Id + "'}");
                    Response.End();
                    return;
                }
                ents.CreateTime = System.DateTime.Now;
                ents.DoUpdate();
            }
            else
            {
                ents          = new ProjectAttendanceDetail();
                ents.UserId   = UserId;
                ents.UserName = UserName;
                if (!string.IsNullOrEmpty(Id))
                {
                    ents.ProjectAttendanceId = Id;
                }
                else
                {
                    ents.ProjectAttendanceId = Pent.Id;
                }
                ents.AttendanceType = SignType;
                ents.AttendanceDate = Convert.ToDateTime(Year + "-" + Month + "-" + day);
                ents.CreateId       = WebPortalService.CurrentUserInfo.UserID;
                ents.CreateName     = WebPortalService.CurrentUserInfo.Name;
                ents.CreateTime     = DateTime.Now;
                ents.DoCreate();
            }
            if (!string.IsNullOrEmpty(Id))
            {
                Response.Write("{success:  true  ,id:'" + Id + "'}");
                Response.End();
                return;
            }
            Response.Write("{success:  true  ,id:'" + Pent.Id + "'}");
            Response.End();
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string         action = Request["action"];
            string         id     = Request["id"];
            string         userid = Request["userid"];
            string         sql    = "";
            DataTable      dt     = null;
            DeptAttendance daEnt  = null;

            if (!string.IsNullOrEmpty(id))
            {
                daEnt = DeptAttendance.Find(id);
            }
            switch (action)
            {
            case "loaddept":
                sql = @"select GroupId as BelongDeptId,REPLACE(Name,'江西瑞林建设监理有限公司','') as BelongDeptName from SysGroup  where GroupId!=228 and GroupId!=267";
                dt  = DataHelper.QueryDataTable(sql);
                string data_dept = JsonHelper.GetJsonString(dt);
                sql = "select value as year from NCRL_Portal..SysEnumeration where ParentId='058fbee9-0a9a-4b25-b343-ea8c05396632' order by SortIndex asc";
                dt  = DataHelper.QueryDataTable(sql);
                string data_year = JsonHelper.GetJsonString(dt);
                sql = "select value as month from NCRL_Portal..SysEnumeration where ParentId='b25e537b-34e3-4437-87af-692e00facd73' order by SortIndex asc";
                dt  = DataHelper.QueryDataTable(sql);
                string data_month = JsonHelper.GetJsonString(dt);
                Response.Write("{'rows':" + data_dept + ", year: " + data_year + ", month: " + data_month + "}");
                Response.End();
                break;

            case "save":
                daEnt = JsonHelper.GetObject <DeptAttendance>(Request["formdata"]);
                if (string.IsNullOrEmpty(daEnt.Id))
                {
                    daEnt.CreateTime = DateTime.Now;
                    daEnt.DoCreate();
                }
                else
                {
                    daEnt = JsonHelper.GetObject <DeptAttendance>(Request["formdata"]);
                    DeptAttendance originalEnt = DeptAttendance.Find(daEnt.Id);
                    EasyDictionary dic         = JsonHelper.GetObject <EasyDictionary>(Request["formdata"]);
                    originalEnt = DataHelper.MergeData <DeptAttendance>(originalEnt, daEnt, dic.Keys);
                    originalEnt.DoUpdate();
                }
                //string where = "";
                //if (!string.IsNullOrEmpty(Request["ProjectName"]))
                //{
                //    where += " and ProjectName like '%" + Request["ProjectName"] + "%')";
                //}
                //if (!string.IsNullOrEmpty(Request["UserName"]))
                //{
                //    where += " and UserName like '%" + Request["UserName"] + "%'";
                //}
                sql = @"select a.* from NCRL_SP..MonAttendance a  left join NCRL_Portal..SysUser b on a.UserId=b.UserId
                    where a.Month='{0}' and a.Year='{1}' and b.Server_IAGUID='" + daEnt.BelongDeptId + "' order by a.ProjectNames asc";
                sql = string.Format(sql, daEnt.Month, daEnt.Year);
                dt  = DataHelper.QueryDataTable(sql);
                string title   = daEnt.BelongDeptName + daEnt.Year + "年" + daEnt.Month + "月考勤表";
                int    runyear = 0;
                if ((daEnt.Year % 4 == 0 && daEnt.Year % 100 != 0) || daEnt.Year % 400 == 0)
                {
                    runyear = 1;
                }
                Response.Write("{success:true,month:'" + daEnt.Month + "',runyear:" + runyear + ",id:'" + daEnt.Id + "',title:'" + title + "',detail:" + JsonHelper.GetJsonString(dt) + "}");
                Response.End();
                break;

            case "loadform":
                daEnt = DeptAttendance.Find(id);
                Response.Write("{success:true,data:" + JsonHelper.GetJsonString(daEnt) + "}");
                Response.End();
                break;

            case "search":
                daEnt        = DeptAttendance.Find(id);
                string where = "";
                if (!string.IsNullOrEmpty(Request["ProjectName"]))
                {
                    where += " and ProjectNames like '%" + Request["ProjectName"] + "%'";
                }
                if (!string.IsNullOrEmpty(Request["UserName"]))
                {
                    where += " and UserName like '%" + Request["UserName"] + "%'";
                }
                sql = @"select a.* from NCRL_SP..MonAttendance a  left join NCRL_Portal..SysUser b on a.UserId=b.UserId
                    where a.Month='{0}' and a.Year='{1}' and b.Server_IAGUID='" + daEnt.BelongDeptId + "' " + where + " order by a.ProjectNames asc";
                sql = string.Format(sql, daEnt.Month, daEnt.Year);
                dt  = DataHelper.QueryDataTable(sql);
                Response.Write("{success:true,rows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "updatedetail":
                string result = Request["SignType"];
                daEnt = DeptAttendance.Find(id);
                sql   = @"select * from NCRL_SP..MonAttendance where UserId='{0}' and Year='{1}' and Month='{2}'";
                sql   = string.Format(sql, Request["UserId"], daEnt.Year, daEnt.Month);
                dt    = DataHelper.QueryDataTable(sql);
                if (dt.Rows.Count == 0)
                {
                    sql = "insert into NCRL_SP..MonAttendance (Id,UserId,UserName,Year,Month," + Request["day"] + ") values('" + Guid.NewGuid() + "','" + Request["UserId"] + "','" + Request["UserName"] + "','" + daEnt.Year + "','" + daEnt.Month + "','" + Request["SignType"] + "')";
                }
                else
                {
                    //如果先前同一个字段标记的是正常上班,再次点正常上班时,清空该字段
                    if (dt.Rows[0][Request["day"]] + "" == Request["SignType"])
                    {
                        sql    = "update NCRL_SP..MonAttendance set " + Request["day"] + "=null where Id='" + dt.Rows[0]["Id"] + "'";
                        result = "";
                    }
                    else
                    {
                        sql    = "update NCRL_SP..MonAttendance set " + Request["day"] + "='" + Request["SignType"] + "' where Id='" + dt.Rows[0]["Id"] + "'";
                        result = Request["SignType"];
                    }
                }
                DataHelper.ExecSql(sql);
                Response.Write("{success:true,result:'" + result + "'}");
                Response.End();
                break;

            case "delete":
                sql = "delete NCRL_SP..ProjectAttendanceDetail where UserId='{0}' and ProjectAttendanceId='{1}' ";
                sql = string.Format(sql, userid, id);
                DataHelper.ExecSql(sql);
                break;
            }
        }