예제 #1
0
 protected void grd_ListUser_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
 {
     string[] para = e.Parameters.Split(',');
     if ((para[0].Equals("Refresh")))
     {
         loadListUsers(trlDepartmentMenu.FocusedNode);
     }
     if (para[0].Equals("Delete"))
     {
         string id = para.Count <string>() == 2 ? para[1] : String.Empty;
         if (id != "")
         {
             DepartmentBO checkID               = new DepartmentBO();
             bool         checkBill             = checkID.checkExistPersonInBill(session, Guid.Parse(id));
             bool         checkVouchesActor     = checkID.checkExistPersonInVouchesActor(session, Guid.Parse(id));
             bool         checkStock            = checkID.checkExistPersonInStockCartActor(session, Guid.Parse(id));
             bool         checkSpecialPrivilege = checkID.checkExistPersonInSpecialPrivilege(session, Guid.Parse(id));
             bool         checkBillActor        = checkID.checkExistPersonInBillActor(session, Guid.Parse(id));
             //bool checkDepartmentPerson = checkID.checkExistPersonInDepartmentPerson(session, Guid.Parse(id));
             //bool checkLoginAccount = checkID.checkExistPersonInLoginAccount(session, Guid.Parse(id));
             if (checkBill || checkVouchesActor || checkStock || checkSpecialPrivilege ||
                 checkBillActor)
             {
                 throw new Exception("Người dùng này không xóa được!");
             }
             else
             {
                 Person p = session.GetObjectByKey <Person>(Guid.Parse(id));
                 if (p != null)
                 {
                     CriteriaOperator criteria = new BinaryOperator("PersonId", p.PersonId, BinaryOperatorType.Equal);
                     XPCollection <DepartmentPerson> dpPersonCL = new XPCollection <DepartmentPerson>(session, criteria);
                     foreach (DepartmentPerson dpPerson in dpPersonCL)
                     {
                         if (dpPerson != null)
                         {
                             dpPerson.RowStatus = -1;
                             dpPerson.Save();
                         }
                     }
                     XPCollection <LoginAccount> lgAccountCL = new XPCollection <LoginAccount>(session, criteria);
                     foreach (LoginAccount lgAccount in lgAccountCL)
                     {
                         if (lgAccount != null)
                         {
                             lgAccount.RowStatus = -1;
                             lgAccount.Save();
                         }
                     }
                     p.RowStatus = -1;
                     p.Save();
                     loadListUsers(trlDepartmentMenu.FocusedNode);
                 }
             }
         }
     }
 }
예제 #2
0
        protected void ASPxGridView_Person_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            e.Cancel = true;
            string id = e.Keys[ASPxGridView_Person.KeyFieldName].ToString();

            if (id.Equals("") || id != null)
            {
                DepartmentBO checkID               = new DepartmentBO();
                bool         checkBill             = checkID.checkExistPersonInBill(session, Guid.Parse(id));
                bool         checkVouchesActor     = checkID.checkExistPersonInVouchesActor(session, Guid.Parse(id));
                bool         checkStock            = checkID.checkExistPersonInStockCartActor(session, Guid.Parse(id));
                bool         checkSpecialPrivilege = checkID.checkExistPersonInSpecialPrivilege(session, Guid.Parse(id));
                bool         checkBillActor        = checkID.checkExistPersonInBillActor(session, Guid.Parse(id));
                //bool checkDepartmentPerson = checkID.checkExistPersonInDepartmentPerson(session, Guid.Parse(id));
                //bool checkLoginAccount = checkID.checkExistPersonInLoginAccount(session, Guid.Parse(id));
                if (checkBill || checkVouchesActor || checkStock || checkSpecialPrivilege ||
                    checkBillActor)
                {
                    throw new Exception("Người dùng này không xóa được!");
                }
                else
                {
                    Person p = session.GetObjectByKey <Person>(Guid.Parse(id));
                    if (p != null)
                    {
                        CriteriaOperator criteria = new BinaryOperator("PersonId", p.PersonId, BinaryOperatorType.Equal);
                        XPCollection <DepartmentPerson> dpPersonCL = new XPCollection <DepartmentPerson>(session, criteria);
                        foreach (DepartmentPerson dpPerson in dpPersonCL)
                        {
                            if (dpPerson != null)
                            {
                                dpPerson.RowStatus = -1;
                                dpPerson.Save();
                            }
                        }
                        XPCollection <LoginAccount> lgAccountCL = new XPCollection <LoginAccount>(session, criteria);
                        foreach (LoginAccount lgAccount in lgAccountCL)
                        {
                            if (lgAccount != null)
                            {
                                lgAccount.RowStatus = -1;
                                lgAccount.Save();
                            }
                        }
                        p.RowStatus = -1;
                        p.Save();
                        loadListUsers(ASPxTreeList_Department2.FocusedNode);
                    }
                }
            }
        }