Ejemplo n.º 1
0
    protected bool IsUserValid()
    {
        ATTUsers objUsers = new ATTUsers(
            this.txtUserName_RQD.Text,
            this.txtPassword_RQD.Text,
            this.txtRePassword_RQD.Text,
            ((ATTUserLogin)Session["Login_User_Detail"]).UserName,
            DateTime.Now,
            (this.txtValidUpto_REDT.Text == "") ? DateTime.Parse("01/01/0001") : DateTime.Parse(this.txtValidUpto_REDT.Text),
            (this.chkActive.Checked == true) ? "Y" : "N",
            "",
            (this.txtPersonID.Text == "") ? 0 : double.Parse(this.txtPersonID.Text)
            );

        ObjectValidation OV = BLLUsers.Validate(objUsers);

        if (OV.IsValid == false)
        {
            this.lblStatusMessage.Text = OV.ErrorMessage;
            this.programmaticModalPopup.Show();
            return(false);
        }


        ATTOrganizationUsers objOrgUser = new ATTOrganizationUsers
                                              (int.Parse(this.DDLOgranization.SelectedValue.ToString()),
                                              txtUserName_RQD.Text,
                                              ((ATTUserLogin)Session["Login_User_Detail"]).UserName,
                                              DateTime.Now.AddYears(1).ToString(),
                                              ""
                                              );


        OV = BLLOrganizationUsers.Validate(objOrgUser);
        if (OV.IsValid == false)
        {
            this.lblStatusMessage.Text = OV.ErrorMessage;
            this.programmaticModalPopup.Show();
            return(false);
        }

        if (BLLUsers.ValidateDate(txtValidUpto_REDT.Text) == false)
        {
            this.lblStatusMessage.Text = "Invalid Date Format:  Date should be in DD/MM/YYYY Format";
            this.programmaticModalPopup.Show();
            return(false);
        }

        return(true);
    }
Ejemplo n.º 2
0
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        try
        {
            if (lstUsers.SelectedIndex == -1)
            {
                List <ATTUsers> lstAllUsers = (List <ATTUsers>)Session["AllUsers"];
                ATTUsers objUser = lstAllUsers.Find
                                   (
                    delegate(ATTUsers usr)
                {
                    return(usr.Username == this.txtUserName_RQD.Text.Trim());
                }
                                   );
                if (objUser != null)
                {
                    this.lblStatusMessage.Text = "User Already Exists.....";
                    this.programmaticModalPopup.Show();
                    return;
                }
            }


            if (IsUserValid() == false)
            {
                return;
            }

            ATTOrganizationUsers objOrgUser;
            if (DDLTransferTo.SelectedIndex == 0)
            {
                objOrgUser = new ATTOrganizationUsers
                             (
                    (DDLTransferTo.SelectedIndex == 0) ? int.Parse(this.DDLOgranization.SelectedValue) : int.Parse(this.DDLTransferTo.SelectedValue),
                    txtUserName_RQD.Text,
                    "",
                    "",
                    (lstUsers.SelectedIndex != -1) ? "E" : "A"
                             );
            }
            else
            {
                objOrgUser = new ATTOrganizationUsers
                             (
                    (DDLTransferTo.SelectedIndex == -1) ? int.Parse(this.DDLOgranization.SelectedValue) : int.Parse(this.DDLTransferTo.SelectedValue),
                    txtUserName_RQD.Text,
                    "",
                    "",
                    "A"
                             );
            }
            string ActvnSts;
            if (DDLTransferTo.SelectedIndex > 0)
            {
                ActvnSts = "N";
            }
            else
            {
                ActvnSts = (chkActive.Checked == true) ? "Y" : "N";
            }
            objOrgUser.ObjUsers = new ATTUsers
                                  (
                this.txtUserName_RQD.Text,
                this.txtPassword_RQD.Text,
                this.txtRePassword_RQD.Text,
                ((ATTUserLogin)Session["Login_User_Detail"]).UserName,
                DateTime.Now,
                DateTime.Parse(this.txtValidUpto_REDT.Text),
                ActvnSts,
                (lstUsers.SelectedIndex != -1) ? "E" : "A",
                (this.txtPersonID.Text == "")?0:double.Parse(this.txtPersonID.Text)
                                  );


            objOrgUser.LSTUserRoles = BLLUserRoles.GetLSTUserRoles(AddUserRoles());


            if (BLLOrganizationUsers.AddOrgUser(objOrgUser) == true)
            {
                if (lstUsers.SelectedIndex != -1)
                {
                    List <ATTOrganization>      lstOrganization = (List <ATTOrganization>)Session["Organization"];
                    List <ATTOrganizationUsers> lstOrgUser      = lstOrganization[this.DDLOgranization.SelectedIndex].LSTOrgUsers;

                    if (DDLTransferTo.SelectedIndex == 0)
                    {
                        //EDITS THE LIST AFTER UPDATE IN THE DATABASE
                        lstOrgUser[lstUsers.SelectedIndex].ObjUsers = new ATTUsers
                                                                      (
                            this.txtUserName_RQD.Text,
                            this.txtPassword_RQD.Text,
                            this.txtRePassword_RQD.Text,
                            ((ATTUserLogin)Session["Login_User_Detail"]).UserName,
                            DateTime.Now,
                            DateTime.Parse(txtValidUpto_REDT.Text),
                            (chkActive.Checked == true) ? "Y" : "N",
                            "E",
                            (this.txtPersonID.Text == "") ? 0 :double.Parse(this.txtPersonID.Text)
                                                                      );

                        lstOrgUser[lstUsers.SelectedIndex].LSTUserRoles.Clear();

                        foreach (GridViewRow gvRow in grdRoles.Rows)
                        {
                            if (gvRow.Cells[5].Text != "R")
                            {
                                ATTUserRoles objUserRoles = new ATTUserRoles
                                                            (
                                    txtUserName_RQD.Text,
                                    int.Parse(gvRow.Cells[0].Text),
                                    (gvRow.Cells[4].Text != "&nbsp;") ? gvRow.Cells[4].Text : (string)Session["NepDate"],
                                    "",
                                    int.Parse(gvRow.Cells[2].Text),
                                    "E"
                                                            );
                                objUserRoles.ObjRoles = new ATTRoles
                                                        (
                                    int.Parse(gvRow.Cells[0].Text),
                                    int.Parse(gvRow.Cells[2].Text),
                                    (string)gvRow.Cells[1].Text,
                                    "",
                                    "E"
                                                        );
                                objUserRoles.ObjApplications = new ATTApplication
                                                               (
                                    int.Parse(gvRow.Cells[2].Text),
                                    "",
                                    gvRow.Cells[3].Text,
                                    "",
                                    "E"
                                                               );

                                lstOrgUser[lstUsers.SelectedIndex].LSTUserRoles.Add(objUserRoles);
                            }
                        }
                    }
                    else if (DDLTransferTo.SelectedIndex > 0)
                    {
                        //TRANSFER TO OTHER ORGANIZATION
                        lstOrgUser[lstUsers.SelectedIndex].LSTUserRoles.Clear();
                        lstOrgUser.RemoveAt(lstUsers.SelectedIndex);

                        //BINDS NEW USERLIST
                        this.lstUsers.DataSource     = lstOrgUser;
                        this.lstUsers.DataTextField  = "Username";
                        this.lstUsers.DataValueField = "Username";
                        this.lstUsers.DataBind();
                    }
                }
                else
                {
                    //ADDS THE NEW USER IN THE LIST

                    List <ATTOrganization>      lstOrganization = (List <ATTOrganization>)Session["Organization"];
                    List <ATTOrganizationUsers> lstOrgUser      = lstOrganization[this.DDLOgranization.SelectedIndex].LSTOrgUsers;
                    List <ATTUserRoles>         lstUserRoles    = new List <ATTUserRoles>();
                    foreach (GridViewRow gvRow in grdRoles.Rows)
                    {
                        if (gvRow.Cells[5].Text != "R")
                        {
                            ATTUserRoles objUserRoles = new ATTUserRoles
                                                        (
                                txtUserName_RQD.Text,
                                int.Parse(gvRow.Cells[0].Text),
                                (string)Session["NepDate"],
                                "",
                                int.Parse(gvRow.Cells[2].Text),
                                "E"
                                                        );
                            objUserRoles.ObjRoles = new ATTRoles
                                                    (
                                int.Parse(gvRow.Cells[0].Text),
                                int.Parse(gvRow.Cells[2].Text),
                                (string)gvRow.Cells[1].Text,
                                "",
                                "E"
                                                    );
                            objUserRoles.ObjApplications = new ATTApplication
                                                           (
                                int.Parse(gvRow.Cells[2].Text),
                                "",
                                gvRow.Cells[3].Text,
                                "",
                                "E"
                                                           );
                            lstUserRoles.Add(objUserRoles);
                        }
                    }

                    ATTOrganizationUsers objOrgUsers = new ATTOrganizationUsers(
                        int.Parse(DDLOgranization.SelectedValue),
                        txtUserName_RQD.Text,
                        "",
                        "",
                        "E"
                        );
                    objOrgUser.LSTUserRoles = lstUserRoles;
                    objOrgUser.ObjUsers     = new ATTUsers
                                              (
                        txtUserName_RQD.Text,
                        txtPassword_RQD.Text,
                        txtRePassword_RQD.Text,
                        ((ATTUserLogin)Session["Login_User_Detail"]).UserName,
                        DateTime.Now,
                        DateTime.Parse(txtValidUpto_REDT.Text),
                        (chkActive.Checked == true) ? "Y" : "N",
                        "E",
                        (this.txtPersonID.Text == "") ? 0 :double.Parse(this.txtPersonID.Text)
                                              );


                    lstOrgUser.Add(objOrgUser);

                    this.lstUsers.DataSource     = lstOrgUser;
                    this.lstUsers.DataTextField  = "Username";
                    this.lstUsers.DataValueField = "Username";
                    this.lstUsers.DataBind();
                }



                txtUserName_RQD.Enabled = true;
                ClearContros();
            }
        }
        catch (Exception ex)
        {
            this.lblStatusMessage.Text = "<CENTER>Error In Saving User..</CENTER><BR><BR>" + ex.ToString();
            this.programmaticModalPopup.Show();
        }
    }