Пример #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     PermissionGroupEntity group = new PermissionGroupEntity();
     group.OID = hdfGroupID.Value;
     group.CUSER = AppCenter.CurrentPersonAccount;
     group.MUSER = AppCenter.CurrentPersonAccount;
     group.GroupCode = txtGroupCode.Text.Trim();
     group.GroupName = txtGroupName.Text.Trim();
     group.GroupStatus = Convert.ToInt32(drpGroupStatus.SelectedValue);
     group.MEMO = txtGroupMemo.Text.Trim();
     bool retValue = true;
     if (string.IsNullOrEmpty(group.OID))
     {
         group.OID = Guid.NewGuid().ToString();
         retValue = new PermissionGroupController().InsertGroup(group);
     }
     else
     {
         retValue = new PermissionGroupController().UpdateGroup(group);
     }
     if (retValue)
     {
         hdfFlag.Value = "1";
         base.ShowMessage(CommonMessage.SaveSuccess);
     }
     else
     {
         base.ShowMessage(CommonMessage.SaveFailed);
     }
 }
        public bool InsertGroup(PermissionGroupEntity group)
        {
            if (group != null)
            {
                string strSQL = @" INSERT INTO dbo.TBLPermissionGroup( oid , groupcode , groupname , groupstatus ,memo,
                                              cuser , cdate , muser ,  mdate , addition1 , addition2 )
                                    VALUES  ( @OID , @GroupCode , @GroupName , @GroupStatus,@Memo,
                                              @Cuser , GETDATE(), @Muser,GETDATE(),NULL, NULL) ";
                string[] paramNames = new string[7];
                object[] paramValues = new object[7];

                paramNames[0] = "OID";
                paramNames[1] = "GroupCode";
                paramNames[2] = "GroupName";
                paramNames[3] = "GroupStatus";
                paramNames[4] = "Memo";
                paramNames[5] = "Cuser";
                paramNames[6] = "Muser";

                paramValues[0] = group.OID;
                paramValues[1] = group.GroupCode;
                paramValues[2] = group.GroupName;
                paramValues[3] = group.GroupStatus;
                paramValues[4] = group.MEMO;
                paramValues[5] = group.CUSER;
                paramValues[6] = group.MUSER;
                SqlDBBroker broker = new SqlDBBroker();
                try
                {
                    broker.Open();
                    broker.BeginTrans();
                    broker.ExecuteNonQuery(strSQL, CommandType.Text, paramNames, paramValues);
                    broker.CommitTrans();
                }
                catch
                {
                    broker.RollbackTrans();
                    return false;
                }
                finally
                {
                    broker.Close();
                }
            }
            return true;
        }
        public PermissionGroupEntity GetGroupInfo(string personID)
        {
            PermissionGroupEntity pe = new PermissionGroupEntity();
            string strSql = @" SELECT * FROM TBLPermissionGroup WHERE oid=@OID  ";
            string[] paramName = new string[1];
            object[] paramValue = new object[1];
            paramName[0] = "OID";

            paramValue[0] = personID;
            SqlDBBroker broker = new SqlDBBroker();
            broker.Open();
            DataSet dst = broker.ExecuteDataset(strSql, CommandType.Text, paramName, paramValue);
            broker.Close();
            if (dst != null && dst.Tables[0] != null && dst.Tables[0].Rows.Count > 0)
            {
                return this.DataRow2Group(dst.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
 private PermissionGroupEntity DataRow2Group(DataRow dr)
 {
     PermissionGroupEntity group = new PermissionGroupEntity();
     if (dr != null)
     {
         group.OID = Convert.ToString(dr["oid"]);
         group.GroupCode = Convert.ToString(dr["groupcode"]);
         group.GroupName = Convert.ToString(dr["groupname"]);
         group.GroupStatus = Convert.ToInt32(dr["groupstatus"]);
         group.MEMO = Convert.ToString(dr["memo"]);
     }
     return group;
 }
        public bool UpdateGroup(PermissionGroupEntity group)
        {
            if (group != null)
            {
                string strSQL = @" UPDATE TBLPermissionGroup SET groupcode=@GroupCode,groupname=@GroupName,groupstatus=@GroupStatus,
                                                memo=@Memo,muser=@Muser,mdate=GETDATE() WHERE oid=@OID   ";
                string[] paramNames = new string[6];
                object[] paramValues = new object[6];

                paramNames[0] = "OID";
                paramNames[1] = "GroupCode";
                paramNames[2] = "GroupName";
                paramNames[3] = "GroupStatus";
                paramNames[4] = "Memo";
                paramNames[5] = "Muser";

                paramValues[0] = group.OID;
                paramValues[1] = group.GroupCode;
                paramValues[2] = group.GroupName;
                paramValues[3] = group.GroupStatus;
                paramValues[4] = group.MEMO;
                paramValues[5] = group.MUSER;
                SqlDBBroker broker = new SqlDBBroker();
                try
                {
                    broker.Open();
                    broker.BeginTrans();
                    broker.ExecuteNonQuery(strSQL, CommandType.Text, paramNames, paramValues);
                    broker.CommitTrans();
                }
                catch
                {
                    broker.RollbackTrans();
                    return false;
                }
                finally
                {
                    broker.Close();
                }
            }
            return true;
        }