Exemple #1
0
        /// <summary>
        /// 获取所选择的GridView行生成DT
        /// </summary>
        private DataTable OnGetSelectRecordTemp()
        {
            //获取用户权限临时表
            var tempdt = dbList.CreateUserPermissionTemp();
            var newrow = tempdt.NewRow();

            newrow[0] = Convert.ToInt32(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[0].Value);                    //UseId
            newrow[1] = Convert.ToString(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[1].Value);                   //用户名称
            newrow[2] = DBNull.Value;                                                                              //用户密码
            newrow[3] = Convert.ToString(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[2].Value);                   //创建人
            newrow[4] = Convert.ToDateTime(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[3].Value);                 //创建日期

            newrow[5]  = Convert.ToString(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[4].Value) == "已启用" ? 0 : 1; //是否启用
            newrow[6]  = Convert.ToString(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[5].Value) == "是" ? 0 : 1;   //能否反审核
            newrow[7]  = Convert.ToString(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[6].Value) == "是" ? 0 : 1;   //能否查阅明细金额
            newrow[8]  = Convert.ToString(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[7].Value) == "是" ? 0 : 1;   //能否对明细物料操作
            newrow[9]  = 1;                                                                                        //是否占用
            newrow[10] = Convert.ToString(gvdtl.Rows[gvdtl.CurrentCell.RowIndex].Cells[8].Value) == "是" ? 0 : 1;   //是否不关联用户
            tempdt.Rows.Add(newrow);
            return(tempdt);
        }
        /// <summary>
        /// 用户权限提交
        /// 注:在操作reluserdt reluserdtldt 及 devgroupdt时,顺序为:先删除后插入=>注:创建状态除外
        /// </summary>
        /// <param name="userdt">用户表</param>
        /// <param name="reluserdt">用户关联表头</param>
        /// <param name="reluserdtldt">用户关联表体</param>
        /// <param name="devgroupdt">关联‘研发类别’表</param>
        /// <returns></returns>
        public bool ImportUserPermissionDt(DataTable userdt, DataTable reluserdt, DataTable reluserdtldt, DataTable devgroupdt)
        {
            var result = true;
            //设置userid变量
            var userid = 0;
            //通过userid是否为0,确定reluserdt 及 reluserdtldt devgroupdt 是否需要执行删除操作(0:不需要 1:需要)
            var markid = 0;

            try
            {
                //获取用户权限临时表
                var tempdt = dbList.CreateUserPermissionTemp();

                //判断若sourcedt内的Userid为0,即需要插入操作,反之,为更新操作
                var dtlrowsLength = userdt.Select("Userid=0").Length;
                //根据情况获取userid
                userid = dtlrowsLength > 0 ? GetUseridKey() : Convert.ToInt32(userdt.Rows[0][0]);
                //确定reluserdt reluserdtldt 及 devgroupdt 是否需要执行删除操作(0:不需要 1:需要)
                markid = dtlrowsLength > 0 ? 0 : 1;

                //对临时表进行添加操作
                var newrow = tempdt.NewRow();
                newrow[0]  = userid;                //UserId
                newrow[1]  = userdt.Rows[0][1];     //用户名称
                newrow[2]  = userdt.Rows[0][2];     //用户密码
                newrow[3]  = userdt.Rows[0][3];     //创建人
                newrow[4]  = userdt.Rows[0][4];     //创建日期
                newrow[5]  = userdt.Rows[0][5];     //是否启用
                newrow[6]  = userdt.Rows[0][6];     //能否反审核
                newrow[7]  = userdt.Rows[0][7];     //能否查阅明细金额
                newrow[8]  = userdt.Rows[0][8];     //能否对明细物料操作
                newrow[9]  = userdt.Rows[0][9];     //是否占用
                newrow[10] = userdt.Rows[0][10];    //是否不关联用户
                tempdt.Rows.Add(newrow);

                //执行插入操作
                if (dtlrowsLength > 0)
                {
                    importDt.ImportDtToDb("T_AD_User", tempdt);
                }
                //执行更新操作
                else
                {
                    importDt.UpdateDbFromDt("T_AD_User", tempdt);
                }

                //执行reluserdt reluserdtldt 及 devgroupdt(注:当表内有值时才执行)
                //注:先根据userid删除对应记录,后插入
                if (reluserdt.Rows.Count > 0)
                {
                    CreateRelUserIntoDb(markid, userid, reluserdt);
                }

                if (reluserdtldt.Rows.Count > 0)
                {
                    CreateRelUserDtlIntoDb(markid, userid, reluserdtldt);
                }

                if (devgroupdt.Rows.Count > 0)
                {
                    CreateRelUserDevGroupIntoDb(markid, userid, devgroupdt);
                }
            }
            catch (Exception)
            {
                result = false;
            }
            return(result);
        }