Exemplo n.º 1
0
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            int seluserid = Convert.ToInt32(ddl_User.SelectedValue);

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        if (this.rp_List.Items.Count > 0)
                        {
                            IFMPLibrary.Entities.Table model = new IFMPLibrary.Entities.Table();
                            model.TaskID       = TaskID;
                            model.TableTypeID  = TType;
                            model.CreateDate   = DateTime.Now;
                            model.CreateUserID = seluserid;
                            model.FlowID       = FlowID;
                            db.Table.Add(model);
                            db.SaveChanges();

                            TextBox         txt_TextName;
                            RadioButtonList rdo_Name;
                            HiddenField     hf_DictionaryID;
                            HiddenField     hf_HintDictionaryID;
                            HiddenField     hf_DType;
                            HiddenField     hf_TableColumnID;
                            Literal         ltl_RegexData;


                            //设置报警的审核人
                            List <User> UserList = db.User.Where(t => t.IsDel != true &&
                                                                 t.UserState != UserState.离职 &&
                                                                 db.TaskFlow.Where(m => m.TaskID == TaskID && db.Flow.Where(l => l.IsAudit == true && l.TableTypeID == TType).Select(l => l.ID).Contains(m.FlowID)).Select(m => m.UserID).Contains(t.ID)).Distinct().ToList();

                            List <TableColumn> TableColumnList = db.TableColumn.Where(t => t.TableTypeID == TType).ToList();
                            TableType          TableType       = db.TableType.FirstOrDefault(t => t.ID == TType);
                            BaseClass          BaseClass       = db.BaseClass.FirstOrDefault(t => t.ID == BaseClassID);
                            User            User         = db.User.FirstOrDefault(t => t.ID == seluserid);
                            List <Flow>     FlowList     = db.Flow.Where(t => t.TableTypeID == TType).ToList();
                            List <TaskFlow> TaskFlowList = db.TaskFlow.Where(t => t.TaskID == TaskID).ToList();

                            for (int i = 0; i < this.rp_List.Items.Count; i++)
                            {
                                TableData tabledata = new TableData();
                                tabledata.IsAlert = false;

                                hf_DType = (HiddenField)rp_List.Items[i].FindControl("hf_DType");
                                int displaytype = Convert.ToInt32(hf_DType.Value);
                                hf_TableColumnID = (HiddenField)rp_List.Items[i].FindControl("hf_TableColumnID");
                                int columnid = Convert.ToInt32(hf_TableColumnID.Value);
                                ltl_RegexData = (Literal)rp_List.Items[i].FindControl("ltl_RegexData");

                                TableColumn tablecolumn = TableColumnList.FirstOrDefault(t => t.ID == columnid);

                                if ((DictionaryTypeEnums)displaytype == DictionaryTypeEnums.单选)
                                {
                                    rdo_Name       = (RadioButtonList)rp_List.Items[i].FindControl("rdo_Name");
                                    tabledata.Data = rdo_Name.SelectedValue.ToString();
                                    //这里也要加一个验证
                                    hf_HintDictionaryID = (HiddenField)rp_List.Items[i].FindControl("hf_HintDictionaryID");
                                    if (!string.IsNullOrEmpty(hf_HintDictionaryID.Value))
                                    {
                                        int    hintdictID  = Convert.ToInt32(hf_HintDictionaryID.Value);
                                        int    selid       = Convert.ToInt32(tabledata.Data);
                                        string defaultdata = db.TableColumn.FirstOrDefault(t => t.ID == columnid).DefaultData;
                                        string seldata     = db.DictionaryData.FirstOrDefault(t => t.ID == selid).Data;
                                        if (defaultdata.Length > 0)
                                        {
                                            if (!defaultdata.Split('|').Contains(seldata))
                                            {
                                                tabledata.IsAlert = true;
                                                if (UserList.Count > 0)
                                                {
                                                    foreach (User NoticeUser in UserList)
                                                    {
                                                        new NoticeDAO().SendDDNotice(
                                                            NoticeUser.DDID,
                                                            new NoticeDAO().GetUrl(Request.Url.AbsoluteUri.ToString(), TaskID, TaskFlowList.FirstOrDefault(t => t.UserID == NoticeUser.ID).FlowID),
                                                            Request.Url.AbsoluteUri.ToString(),
                                                            "报警",
                                                            tablecolumn.ColumnName + "存在异常",
                                                            "请及时去现场查看情况",
                                                            new NoticeDAO().BuildFormList(TableType.Name, tablecolumn.ColumnName, tabledata.Data, BaseClass.Name, User.RealName));
                                                    }
                                                }
                                                //new NoticeDAO().SendDDNotice();
                                            }
                                        }
                                        //List<DictionaryData> DictionaryDataList = db.DictionaryData.Where(t => t.DictionaryID == hintdictID).ToList();
                                    }
                                }
                                else
                                {
                                    txt_TextName   = (TextBox)rp_List.Items[i].FindControl("txt_TextName");
                                    tabledata.Data = txt_TextName.Text.ToString();
                                    if (string.IsNullOrEmpty(tabledata.Data))
                                    {
                                        ShowMessage("请确认已填写所有的数据");
                                        ts.Dispose();
                                        return;
                                    }
                                    //验证合法性
                                    hf_DictionaryID = (HiddenField)rp_List.Items[i].FindControl("hf_DictionaryID");
                                    if (!string.IsNullOrEmpty(hf_DictionaryID.Value))
                                    {
                                        int        dictID  = Convert.ToInt32(hf_DictionaryID.Value);
                                        Dictionary diction = db.Dictionary.FirstOrDefault(t => t.ID == dictID);
                                        if (diction != null)
                                        {
                                            if (new BaseUtils().GetRegex(tabledata.Data, diction.RegexType.Value) == false)
                                            {
                                                ShowMessage("【" + tabledata.Data + "】数据填写错误,请填写【" + diction.RegexType + "】");
                                                ts.Dispose();
                                                return;
                                            }
                                        }
                                    }

                                    hf_HintDictionaryID = (HiddenField)rp_List.Items[i].FindControl("hf_HintDictionaryID");
                                    if (!string.IsNullOrEmpty(hf_HintDictionaryID.Value))
                                    {
                                        int        hintdictID  = Convert.ToInt32(hf_HintDictionaryID.Value);
                                        Dictionary hintdiction = db.Dictionary.FirstOrDefault(t => t.ID == hintdictID);

                                        if (hintdiction != null)
                                        {
                                            if (hintdiction.RegexType == RegexType.范围的数字 || hintdiction.RegexType == RegexType.范围的度数)
                                            {
                                                if (new BaseUtils().GetRegex(tabledata.Data.Split('°')[0], hintdiction.RegexType.Value, hintdiction.RegexData) == false)
                                                {
                                                    tabledata.IsAlert = true;
                                                    if (UserList.Count > 0)
                                                    {
                                                        foreach (User NoticeUser in UserList)
                                                        {
                                                            new NoticeDAO().SendDDNotice(
                                                                NoticeUser.DDID,
                                                                new NoticeDAO().GetUrl(Request.Url.AbsoluteUri.ToString(), TaskID, TaskFlowList.FirstOrDefault(t => t.UserID == NoticeUser.ID).FlowID),
                                                                Request.Url.AbsoluteUri.ToString(),
                                                                "报警",
                                                                tablecolumn.ColumnName + "存在异常",
                                                                "请及时去现场查看情况",
                                                                new NoticeDAO().BuildFormList(TableType.Name, tablecolumn.ColumnName, tabledata.Data, BaseClass.Name, User.RealName));
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (new BaseUtils().GetRegex(tabledata.Data, hintdiction.RegexType.Value) == false)
                                                {
                                                    tabledata.IsAlert = true;
                                                    if (UserList.Count > 0)
                                                    {
                                                        foreach (User NoticeUser in UserList)
                                                        {
                                                            new NoticeDAO().SendDDNotice(
                                                                NoticeUser.DDID,
                                                                new NoticeDAO().GetUrl(Request.Url.AbsoluteUri.ToString(), TaskID, TaskFlowList.FirstOrDefault(t => t.UserID == NoticeUser.ID).FlowID),
                                                                Request.Url.AbsoluteUri.ToString(),
                                                                "报警",
                                                                tablecolumn.ColumnName + "存在异常",
                                                                "请及时去现场查看情况",
                                                                new NoticeDAO().BuildFormList(TableType.Name, tablecolumn.ColumnName, tabledata.Data, BaseClass.Name, User.RealName));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                tabledata.TableID       = model.ID;
                                tabledata.TableColumnID = columnid;
                                tabledata.CreateDate    = DateTime.Now;
                                tabledata.CreateUserID  = seluserid;

                                db.TableData.Add(tabledata);
                                db.SaveChanges();
                            }

                            //添加可能存在的不填写内容
                            List <TableColumn> NotFillColumnList = db.TableColumn.Where(t => t.IsFill == false && t.TableTypeID == model.TableTypeID).ToList();
                            foreach (TableColumn NotFillColumn in NotFillColumnList)
                            {
                                TableData tabledata = new TableData();
                                tabledata.CreateDate    = DateTime.Now;
                                tabledata.CreateUserID  = seluserid;
                                tabledata.TableColumnID = NotFillColumn.ID;
                                tabledata.TableID       = model.ID;
                                //获取数值和合法性
                                tabledata.Data = new ColumnDAO().GetData(model.ID, NotFillColumn).ToString();
                                //需要报警
                                tabledata.IsAlert = false;
                                if (NotFillColumn.HintDictionaryID != null)
                                {
                                    Dictionary hintdiction = db.Dictionary.FirstOrDefault(t => t.ID == NotFillColumn.HintDictionaryID);

                                    if (hintdiction != null)
                                    {
                                        if (hintdiction.RegexType == RegexType.范围的数字 || hintdiction.RegexType == RegexType.范围的度数)
                                        {
                                            if (new BaseUtils().GetRegex(tabledata.Data.Split('°')[0], hintdiction.RegexType.Value, hintdiction.RegexData) == false)
                                            {
                                                tabledata.IsAlert = true;
                                                if (UserList.Count > 0)
                                                {
                                                    foreach (User NoticeUser in UserList)
                                                    {
                                                        new NoticeDAO().SendDDNotice(
                                                            NoticeUser.DDID,
                                                            new NoticeDAO().GetUrl(Request.Url.AbsoluteUri.ToString(), TaskID, TaskFlowList.FirstOrDefault(t => t.UserID == NoticeUser.ID).FlowID),
                                                            Request.Url.AbsoluteUri.ToString(),
                                                            "报警",
                                                            NotFillColumn.ColumnName + "存在异常",
                                                            "请及时去现场查看情况",
                                                            new NoticeDAO().BuildFormList(TableType.Name, NotFillColumn.ColumnName, tabledata.Data, BaseClass.Name, User.RealName));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (new BaseUtils().GetRegex(tabledata.Data, hintdiction.RegexType.Value) == false)
                                            {
                                                tabledata.IsAlert = true;
                                                if (UserList.Count > 0)
                                                {
                                                    foreach (User NoticeUser in UserList)
                                                    {
                                                        new NoticeDAO().SendDDNotice(
                                                            NoticeUser.DDID,
                                                            new NoticeDAO().GetUrl(Request.Url.AbsoluteUri.ToString(), TaskID, TaskFlowList.FirstOrDefault(t => t.UserID == NoticeUser.ID).FlowID),
                                                            Request.Url.AbsoluteUri.ToString(),
                                                            "报警",
                                                            NotFillColumn.ColumnName + "存在异常",
                                                            "请及时去现场查看情况",
                                                            new NoticeDAO().BuildFormList(TableType.Name, NotFillColumn.ColumnName, tabledata.Data, BaseClass.Name, User.RealName));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }


                                db.TableData.Add(tabledata);
                                db.SaveChanges();
                            }


                            #region 更新taskflow表信息
                            TaskFlow taskflow = db.TaskFlow.FirstOrDefault(t => t.TaskID == TaskID && t.FlowID == FlowID && t.UserID == seluserid);
                            if (taskflow != null)
                            {
                                taskflow.ApplyDate = DateTime.Now;
                                if (DateTime.Now > taskflow.EndDate)
                                {
                                    taskflow.ApplyType = ApplyTypeEnums.迟交;
                                }
                                else
                                {
                                    taskflow.ApplyType = ApplyTypeEnums.正常;
                                }
                            }
                            db.SaveChanges();
                            #endregion
                        }
                        else
                        {
                            ShowMessage("暂无表单信息,无需提交");
                            ts.Dispose();
                            return;
                        }
                        ShowMessagePad();
                        new SysLogDAO().AddLog(LogType.操作日志_添加, "成功填写【" + this.ltl_TableType.Text + "】表单信息", seluserid);
                        ts.Complete();
                    }
                    catch
                    {
                        ShowMessage("提交失败");
                        new SysLogDAO().AddLog(LogType.操作日志_添加, "填写【" + this.ltl_TableType.Text + "】表单信息时出错", seluserid);
                        ts.Dispose();
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
                new SysLogDAO().AddLog(LogType.系统日志, ex.Message, seluserid);
                return;
            }
        }
Exemplo n.º 2
0
        protected void rp_List_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Task         model          = db.Task.FirstOrDefault(t => t.ID == TaskID);
                int          clatype        = Convert.ToInt32(model.ClassType);   //班次类型
                int          tabtype        = Convert.ToInt32(model.TableTypeID); //表单类型
                HiddenField  hfFlowID       = (HiddenField)e.Item.FindControl("hf_FlowID");
                int          flowid         = Convert.ToInt32(hfFlowID.Value);
                CheckBoxList chk            = (CheckBoxList)e.Item.FindControl("chk_ClassList");
                Literal      ltl_SysUser    = (Literal)e.Item.FindControl("ltl_SysUser");
                Literal      ltl_BeginDate  = (Literal)e.Item.FindControl("ltl_BeginDate");
                Literal      ltl_EndDate    = (Literal)e.Item.FindControl("ltl_EndDate");
                Literal      ltl_RemindDate = (Literal)e.Item.FindControl("ltl_RemindDate");

                //根据班次类型获取所有班次信息
                List <BaseClass>     classlist         = db.BaseClass.Where(t => t.ClassType == (ClassTypeEnums)clatype && t.IsDel != true).ToList();
                List <BaseClassUser> bassclassuserlist = db.BaseClassUser.ToList();
                List <object>        list = new List <object>();
                if (classlist.Count > 0)
                {
                    List <User> UserList = db.User.Where(t => t.IsDel != true).ToList();
                    foreach (BaseClass bclass in classlist)
                    {//根据班次ID和流程ID获取班次人员信息,绑定CheckBoxlist
                        string name = "";
                        List <BaseClassUser> classuserlist = bassclassuserlist.Where(t => t.BaseClassID == bclass.ID && t.FlowID == flowid).ToList();
                        if (classuserlist.Count > 0)
                        {
                            foreach (BaseClassUser classuser in classuserlist)
                            {
                                name += UserList.FirstOrDefault(t => t.ID == classuser.UserID) == null ? "" : (UserList.FirstOrDefault(t => t.ID == classuser.UserID).RealName + ",");
                            }
                        }
                        name = name.TrimEnd(',').TrimStart(',');
                        list.Add(new
                        {
                            Name = bclass.Name + "(" + name + ")",
                            bclass.ID
                        });
                    }
                }
                if (list.Count > 0)
                {
                    chk.DataTextField  = "Name";
                    chk.DataValueField = "ID";
                    chk.DataSource     = list;
                    chk.DataBind();
                }

                List <TaskFlow> taskflowlist = db.TaskFlow.Where(t => t.TaskID == TaskID && t.FlowID == flowid).ToList();
                if (taskflowlist.Count > 0)
                {
                    //获取taskflow表的班次信息
                    var testlist = taskflowlist.Where(t => t.BaseClassID != null).Select(t => t.BaseClassID).Distinct().ToList();
                    for (int i = 0; i < testlist.Count; i++)
                    {
                        int classid = Convert.ToInt32(testlist[i].ToString());
                        for (int j = 0; j < chk.Items.Count; j++)
                        {
                            if (chk.Items[j].Value == classid.ToString())
                            {
                                chk.Items[j].Selected = true;
                            }
                        }
                        TaskFlow taskflow = taskflowlist.FirstOrDefault(t => t.BaseClassID == classid);
                        if (taskflow != null)
                        {
                            ltl_BeginDate.Text  = taskflow.BeginDate.ToString("yyyy-MM-dd HH:mm:ss");
                            ltl_EndDate.Text    = taskflow.EndDate.ToString("yyyy-MM-dd HH:mm:ss");
                            ltl_RemindDate.Text = taskflow.RemindDate.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    string          name     = "";
                    List <TaskFlow> flowlist = taskflowlist.Where(t => t.BaseClassID == null).ToList();
                    foreach (TaskFlow taskflow in flowlist)
                    {
                        name += db.User.FirstOrDefault(t => t.ID == taskflow.UserID && t.IsDel != true) == null ? "" : (db.User.FirstOrDefault(t => t.ID == taskflow.UserID && t.IsDel != true).RealName + ",");
                    }
                    ltl_SysUser.Text = name.TrimEnd(',').TrimStart(',');
                }

                Repeater      rp_TableList = (Repeater)e.Item.FindControl("rp_TableList");
                List <object> lists        = new List <object>();
                if (taskflowlist != null)
                {
                    foreach (TaskFlow tflist in taskflowlist)
                    {
                        IFMPLibrary.Entities.Table table = db.Table.FirstOrDefault(t => t.TaskID == TaskID && t.TableTypeID == tabtype && t.CreateUserID == tflist.UserID);
                        if (table != null)
                        {
                            lists.Add(new
                            {
                                table.ID,
                                CreateUser = table.CreateUserID,
                                UserName   = db.User.FirstOrDefault(t => t.ID == table.CreateUserID).RealName,
                                table.CreateDate
                            });
                        }
                        else
                        {
                            lists.Add(new
                            {
                                ID         = -2,
                                CreateUser = tflist.UserID,
                                UserName   = db.User.FirstOrDefault(t => t.ID == tflist.UserID).RealName,
                                CreateDate = ""
                            });
                        }
                    }
                }
                if (lists.Count() > 0)
                {
                    rp_TableList.DataSource = lists.ToList();
                    rp_TableList.DataBind();
                }
            }
        }