Ejemplo n.º 1
0
        /// <summary>
        /// 判別程式的CRUD權限
        /// </summary>
        /// <param name="ParameterList">輸入變數</param>
        /// <returns>回傳程式的CRUD權限</returns>
        public DataTable QueryProgramCRUD(ArrayList ParameterList)
        {
            try
            {
                int i = 0;
                int j = 0;

                SYS_ROLEPROGAUTHRELDBO rolepg = new SYS_ROLEPROGAUTHRELDBO(ref USEDB);
                SYS_USERPROGAUTHRELDBO userpg = new SYS_USERPROGAUTHRELDBO(ref USEDB);

                //抓取角色設定目前程式的狀態
                DataTable RolePGDt = rolepg.doQueryByProgramCode(ParameterList);

                //抓取使用者設定目前程式的狀態
                DataTable UserPGDt = userpg.doQueryByProgramCode(ParameterList);

                //建立回傳資訊
                DataTable Dt = new DataTable("ProgCRUD");

                DataColumn dc = new DataColumn("Code");
                DataColumn dc1 = new DataColumn("CanCreate");
                DataColumn dc2 = new DataColumn("CanRead");
                DataColumn dc3 = new DataColumn("CanUpdate");
                DataColumn dc4 = new DataColumn("CanDelete");
                Dt.Columns.Add(dc);
                Dt.Columns.Add(dc1);
                Dt.Columns.Add(dc2);
                Dt.Columns.Add(dc3);
                Dt.Columns.Add(dc4);

                //使用者權限設定不為空的
                if (UserPGDt.Rows.Count > 0)
                {
                    DataRow Dr = Dt.NewRow();
                    Dr["Code"] = UserPGDt.Rows[0]["Code"];
                    Dr["CanCreate"] = UserPGDt.Rows[0]["CanCreate"];
                    Dr["CanRead"] = UserPGDt.Rows[0]["CanRead"];
                    Dr["CanUpdate"] = UserPGDt.Rows[0]["CanUpdate"];
                    Dr["CanDelete"] = UserPGDt.Rows[0]["CanDelete"];
                    Dt.Rows.Add(Dr);
                }

                if (Dt.Rows.Count > 0)
                {
                    if (RolePGDt.Rows.Count > 0)
                    {                                                                        
                        Dt.Rows[0]["CanCreate"] = (Dt.Rows[0]["CanCreate"].ToString() == "1") ? Dt.Rows[0]["CanCreate"] : RolePGDt.Rows[0]["CanCreate"];
                        Dt.Rows[0]["CanRead"] = (Dt.Rows[0]["CanRead"].ToString() == "1") ? Dt.Rows[0]["CanRead"] : RolePGDt.Rows[0]["CanRead"];
                        Dt.Rows[0]["CanUpdate"] = (Dt.Rows[0]["CanUpdate"].ToString() == "1") ? Dt.Rows[0]["CanUpdate"] : RolePGDt.Rows[0]["CanUpdate"];
                        Dt.Rows[0]["CanDelete"] = (Dt.Rows[0]["CanDelete"].ToString() == "1") ? Dt.Rows[0]["CanDelete"] : RolePGDt.Rows[0]["CanDelete"];                        
                    }
                }
                else
                {
                    if (RolePGDt.Rows.Count > 0)
                    {
                        DataRow Dr = Dt.NewRow();
                        Dr["Code"] = RolePGDt.Rows[0]["Code"];
                        Dr["CanCreate"] = RolePGDt.Rows[0]["CanCreate"];
                        Dr["CanRead"] = RolePGDt.Rows[0]["CanRead"];
                        Dr["CanUpdate"] = RolePGDt.Rows[0]["CanUpdate"];
                        Dr["CanDelete"] = RolePGDt.Rows[0]["CanDelete"];
                        Dt.Rows.Add(Dr);
                    }
                }
                return Dt;

            }
            catch(Exception ex)
            {
                throw ex;
            }
        }