protected void Page_Load(object sender, EventArgs e)
    {
        //admin olub olmadigin yoxlayaq
        if (DALC._GetAdministratorsLogin.UsersStatusID != 30 && DALC._GetAdministratorsLogin.UsersStatusID != 25)
        {
            LnkNew.Visible = false;
            GrdAuditsOrganizations.Columns[GrdAuditsOrganizations.Columns.Count - 1].Visible = false;
            GrdAuditsOrganizations.Columns[GrdAuditsOrganizations.Columns.Count - 3].Visible = false;
        }

        if (string.IsNullOrEmpty(Config._GetQueryString("p")))
        {
            Session[_FilterSessionName] = null;
        }
        if (!this.IsPostBack)
        {
            DlistRegionalCenter.DataSource = DALC.GetRegionalCenters();
            DlistRegionalCenter.DataBind();
            DlistRegionalCenter.Items.Insert(0, new ListItem("--", "-1"));
            DListSubOrganization.DataSource = DALC.GetOrganizationSub("-1");
            DListSubOrganization.DataBind();
            DListSubOrganization.Items.Insert(0, new ListItem("--", "-1"));
            DlistVisitType.DataSource = DALC.GetVisitTypes();
            DlistVisitType.DataBind();
            DlistVisitType.Items.Insert(0, new ListItem("--", "-1"));

            DlistRegionalCenterFilter.DataSource = DALC.GetRegionalCenters();
            DlistRegionalCenterFilter.DataBind();
            DlistRegionalCenterFilter.Items.Insert(0, new ListItem("--", "-1"));


            DListParentOrganizationFilter.DataSource = DALC.GetOrganizationTop();
            DListParentOrganizationFilter.DataBind();
            DListParentOrganizationFilter.Items.Insert(0, new ListItem("--", "-1"));

            DlistTopOrganization.DataSource = DALC.GetOrganizationTop();
            DlistTopOrganization.DataBind();
            DlistTopOrganization.Items.Insert(0, new ListItem("--", "-1"));


            DListTopOrganizationFilter_SelectedIndexChanged(null, null);
            DlistTopOrganization_SelectedIndexChanged(null, null);

            DlistVisitTypeFilter.DataSource = DALC.GetVisitTypes();
            DlistVisitTypeFilter.DataBind();
            DlistVisitTypeFilter.Items.Insert(0, new ListItem("--", "-1"));

            DlistUsers.DataSource = DALC.GetUsers();
            DlistUsers.DataBind();
            BindGrid();
        }
    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        //admin olub olmadigin yoxlayaq
        if (DALC._GetAdministratorsLogin.UsersStatusID != 30 && DALC._GetAdministratorsLogin.UsersStatusID != 25)
        {
            return;
        }

        if (DlistRegionalCenter.SelectedValue == "-1")
        {
            Config.MsgBoxAjax("Regional mərkəzi daxil edin.");
            ShowPopup();
            return;
        }
        if (DListSubOrganization.SelectedValue == "-1")
        {
            Config.MsgBoxAjax("Qurumu daxil edin.");
            ShowPopup();
            return;
        }
        if (DlistVisitType.SelectedValue == "-1")
        {
            Config.MsgBoxAjax("Başçəkmənin formasını daxil edin.");
            ShowPopup();
            return;
        }
        if (string.IsNullOrEmpty(TxtProblems.Text.Trim()))
        {
            Config.MsgBoxAjax("Aşkar edilmiş problemləri daxil edin.");
            ShowPopup();
            return;
        }
        if (string.IsNullOrEmpty(TxtSuggestion.Text.Trim()))
        {
            Config.MsgBoxAjax("Tövsiyəni daxil edin.");
            ShowPopup();
            return;
        }

        object DtVisit = TxtVisitDate.Text.DateTimeFormat();

        if (DtVisit == null)
        {
            Config.MsgBoxAjax("Baxışın həyata keçirildiyi tarixi düzgün seçin.");
            ShowPopup();
            return;
        }


        int result = -1;

        if (ViewState["operation"]._ToString() == "new")
        {
            result = DALC.InsertAuditsOrganizations(
                DALC._GetAdministratorsLogin.ID,
                DlistRegionalCenter.SelectedValue,
                DListSubOrganization.SelectedValue,
                DlistVisitType.SelectedValue,
                TxtProblems.Text,
                TxtSuggestion.Text,
                TxtDescription.Text, (DateTime)DtVisit);
        }

        else if (ViewState["operation"]._ToString() == "edit")
        {
            result = DALC.UpdateAuditOrganizations(ViewState["AuditsOrganizationsID"]._ToString(), DlistRegionalCenter.SelectedValue, DListSubOrganization.SelectedValue,
                                                   DlistVisitType.SelectedValue, TxtProblems.Text, TxtSuggestion.Text, TxtDescription.Text, (DateTime)DtVisit);
        }

        if (result > 0)
        {
            int AuditsOrganizationsID = ViewState["operation"]._ToString() == "new" ? result : ViewState["AuditsOrganizationsID"]._ToInt32();

            //Duzgun update oluna bilmesi ucun her ehtimala qarsi bu AuditsOrganizations-a aid butun userleri evvelce silib sonra tezden insert edek
            if (ViewState["operation"]._ToString() == "edit")
            {
                DALC.DeleteAuditsOrganizationsUsers(AuditsOrganizationsID);
            }

            if (DlistUsers.GetSelectedIndices().Count() > 0)
            {
                for (int i = 0; i <= (DlistUsers.Items.Count - 1); i++)
                {
                    if (DlistUsers.Items[i].Selected)
                    {
                        string SelectedUserId = DlistUsers.Items[i].Value;

                        DALC.InsertAuditsOrganizationsUsers(AuditsOrganizationsID, SelectedUserId._ToInt32());
                    }
                }
            }

            Config.MsgBoxAjax(ViewState["operation"]._ToString() == "new" ? "Məlumatlar qeydə alındı." : "Məlumatlar redaktə edildi.", true);
            BindGrid();
        }
        else
        {
            Config.MsgBoxAjax(Config._DefaultErrorMessages);
        }
    }