/// <summary>
 /// Link Gove code click handler
 /// to allow edit this gov
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void lnkDelete_Click(object sender, EventArgs e)
 {
     LinkButton lnk = (LinkButton)sender;
     CIVIL_OFFICE delpolice = new CIVIL_OFFICE();
     delpolice.LoadByPrimaryKey(short.Parse(lnk.CommandArgument));
     delpolice.MarkAsDeleted();
     delpolice.Save();
     Filter();
 }
 protected void uiDropDownListGov_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (uiDropDownListGov.SelectedIndex != 0)
     {
         CIVIL_OFFICE pol = new CIVIL_OFFICE();
         pol.Where.FK_GOVCD.Value = short.Parse(uiDropDownListGov.SelectedValue);
         pol.Where.FK_GOVCD.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
         pol.Query.AddOrderBy(CIVIL_OFFICE.ColumnNames.DESCR, MyGeneration.dOOdads.WhereParameter.Dir.ASC);
         pol.Query.Load();
         uiDropDownListCivil.DataSource = pol.DefaultView;
         uiDropDownListCivil.DataTextField = POLICE_STATION.ColumnNames.DESCR;
         uiDropDownListCivil.DataValueField = POLICE_STATION.ColumnNames.CD;
         uiDropDownListCivil.DataBind();
         uiDropDownListCivil.Items.Insert(0, new ListItem("---"));
         uiDropDownListCivil.SelectedIndex = 0;
     }
 }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     CIVIL_OFFICE objpolice = new CIVIL_OFFICE();
     if (txtCivilCode.ReadOnly)
     {
         try
         {
             // update case
             objpolice.LoadByPrimaryKey(short.Parse(txtCivilCode.Text));
             objpolice.DESCR = txtCivilName.Text;
             objpolice.FK_GOVCD = short.Parse(drpGove.SelectedValue);
             objpolice.Save();
             txtCivilCode.ReadOnly = false;
             Filter();
             //txtFilter.Text = "";
             txtCivilCode.Text = "";
             txtCivilName.Text = "";
             btnSave.Text = "اضافة";
         }
         catch
         {
             MHOCommon.ShowMessage("لقد حاولت ادخال اسم ادارة موجود من قبل", this.Page);
         }
     }
     else
     {
         try
         {
             //Insert case
             objpolice.AddNew();
             objpolice.CD = short.Parse(txtCivilCode.Text);
             objpolice.DESCR = txtCivilName.Text;
             objpolice.FK_GOVCD = short.Parse(drpGove.SelectedValue);
             objpolice.Save();
             Filter();
             //txtFilter.Text = "";
             txtCivilCode.Text = "";
             txtCivilName.Text = "";
         }
         catch
         {
             MHOCommon.ShowMessage("لقد حاولت ادخال كود موجود او اسم الادارة موجود من قبل", this.Page);
         }
     }
 }
    /// <summary>
    /// Link Gove code click handler
    /// to allow edit this gov
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lnkDelete_Click(object sender, EventArgs e)
    {
        LinkButton lnk = (LinkButton)sender;
        POLICE_STATION pol = new POLICE_STATION();
        pol.Where.FK_GOVCD.Value = short.Parse(lnk.CommandArgument);
        pol.Where.FK_GOVCD.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
        CIVIL_OFFICE civ = new CIVIL_OFFICE();
        civ.Where.FK_GOVCD.Value = short.Parse(lnk.CommandArgument);
        civ.Where.FK_GOVCD.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;

        if (!pol.Query.Load() && !civ.Query.Load())
        {
            GOVERNORATE delgov = new GOVERNORATE();
            delgov.LoadByPrimaryKey(short.Parse(lnk.CommandArgument));
            delgov.MarkAsDeleted();
            delgov.Save();
            Filter("");
        }
        else
        {
            MHOCommon.ShowMessage("خطأ فى الحذف بسبب البيانات المرتبطة", this.Page);
        }
    }
    private void LoadLookups()
    {
        GOVERNORATE gov = new GOVERNORATE();
        gov.LoadAll();

        uiDropDownListGov.DataSource = gov.DefaultView;
        uiDropDownListGov.DataTextField = GOVERNORATE.ColumnNames.DESCR;
        uiDropDownListGov.DataValueField = GOVERNORATE.ColumnNames.CD;
        uiDropDownListGov.DataBind();
        uiDropDownListGov.Items.Insert(0, new ListItem("---"));
        uiDropDownListGov.SelectedIndex = 0;

        uiDropDownListMachineGov.DataSource = gov.DefaultView;
        uiDropDownListMachineGov.DataTextField = GOVERNORATE.ColumnNames.DESCR;
        uiDropDownListMachineGov.DataValueField = GOVERNORATE.ColumnNames.CD;
        uiDropDownListMachineGov.DataBind();
        uiDropDownListMachineGov.Items.Insert(0, new ListItem("---"));
        uiDropDownListMachineGov.SelectedIndex = 0;

        CIVIL_OFFICE pol = new CIVIL_OFFICE();
        pol.LoadAll();
        uiDropDownListCivil.DataSource = pol.DefaultView;
        uiDropDownListCivil.DataTextField = POLICE_STATION.ColumnNames.DESCR;
        uiDropDownListCivil.DataValueField = POLICE_STATION.ColumnNames.CD;
        uiDropDownListCivil.DataBind();
        uiDropDownListCivil.Items.Insert(0, new ListItem("---"));
        uiDropDownListCivil.SelectedIndex = 0;

        uiDropDownListMachineCivil.DataSource = pol.DefaultView;
        uiDropDownListMachineCivil.DataTextField = POLICE_STATION.ColumnNames.DESCR;
        uiDropDownListMachineCivil.DataValueField = POLICE_STATION.ColumnNames.CD;
        uiDropDownListMachineCivil.DataBind();
        uiDropDownListMachineCivil.Items.Insert(0, new ListItem("---"));
        uiDropDownListMachineCivil.SelectedIndex = 0;

        health_office obj = new health_office();
        obj.LoadAll();
        uiDropDownListHealthOffice.DataSource = obj.DefaultView;
        uiDropDownListHealthOffice.DataTextField = health_office.ColumnNames.HEALTHDESCR;
        uiDropDownListHealthOffice.DataValueField = health_office.ColumnNames.HEALTHCD;
        uiDropDownListHealthOffice.DataBind();
        uiDropDownListHealthOffice.Items.Insert(0, new ListItem("---"));
        uiDropDownListHealthOffice.SelectedIndex = 0;

        uiDropDownListMachineHealthOffice.DataSource = obj.DefaultView;
        uiDropDownListMachineHealthOffice.DataTextField = health_office.ColumnNames.HEALTHDESCR;
        uiDropDownListMachineHealthOffice.DataValueField = health_office.ColumnNames.HEALTHCD;
        uiDropDownListMachineHealthOffice.DataBind();
        uiDropDownListMachineHealthOffice.Items.Insert(0, new ListItem("---"));
        uiDropDownListMachineHealthOffice.SelectedIndex = 0;
    }
 private void LoadCivilByGov()
 {
     CIVIL_OFFICE civil = new CIVIL_OFFICE();
     civil.Where.FK_GOVCD.Value = drpGov.SelectedValue;
     civil.Query.Load();
     drpCivil.DataTextField = CIVIL_OFFICE.ColumnNames.DESCR;
     drpCivil.DataValueField = CIVIL_OFFICE.ColumnNames.CD;
     drpCivil.DataSource = civil.DefaultView;
     drpCivil.DataBind();
     drpCivil.Items.Insert(0, new ListItem("اختر ادارة", "-1"));
 }
 private void loadAllCivil()
 {
     CIVIL_OFFICE civil = new CIVIL_OFFICE();
     civil.LoadAll();
     drpCivil.DataTextField = CIVIL_OFFICE.ColumnNames.DESCR;
     drpCivil.DataValueField = CIVIL_OFFICE.ColumnNames.CD;
     drpCivil.DataSource = civil.DefaultView;
     drpCivil.DataBind();
     drpCivil.Items.Insert(0, new ListItem("اختر ادارة", "-1"));
 }
    private void setCurrentUserInfo()
    {
        try
        {
            OrgUser Current = new OrgUser();
            if (MHOCommon.CurrentLoggedUserID != null && MHOCommon.CurrentLoggedUserID != Guid.Empty)
            {
                Current.LoadByPrimaryKey(MHOCommon.CurrentLoggedUserID);
                uiTextBoxNotifierName.Text = Current.FirstName.Trim() + " " + Current.FatherName.Trim();

                if (Current.GovId != 0)
                {
                    uiDropDownListGov.SelectedValue = Current.GovId.ToString();
                    uiDropDownListGov.Enabled = false;
                    uiDropDownListMachineGov.SelectedValue = Current.GovId.ToString();
                    uiDropDownListMachineGov.Enabled = false;

                    /*********************/
                    if (uiDropDownListGov.SelectedIndex != 0)
                    {
                        CIVIL_OFFICE pol = new CIVIL_OFFICE();
                        pol.Where.FK_GOVCD.Value = short.Parse(uiDropDownListGov.SelectedValue);
                        pol.Where.FK_GOVCD.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                        pol.Query.AddOrderBy(CIVIL_OFFICE.ColumnNames.DESCR, MyGeneration.dOOdads.WhereParameter.Dir.ASC);
                        pol.Query.Load();
                        uiDropDownListCivil.DataSource = pol.DefaultView;
                        uiDropDownListCivil.DataTextField = POLICE_STATION.ColumnNames.DESCR;
                        uiDropDownListCivil.DataValueField = POLICE_STATION.ColumnNames.CD;
                        uiDropDownListCivil.DataBind();
                        uiDropDownListCivil.Items.Insert(0, new ListItem("---", "0"));
                        uiDropDownListCivil.SelectedIndex = 0;
                    }

                    if (uiDropDownListMachineGov.SelectedIndex != 0)
                    {
                        CIVIL_OFFICE pol = new CIVIL_OFFICE();
                        pol.Where.FK_GOVCD.Value = short.Parse(uiDropDownListMachineGov.SelectedValue);
                        pol.Where.FK_GOVCD.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
                        pol.Query.AddOrderBy(CIVIL_OFFICE.ColumnNames.DESCR, MyGeneration.dOOdads.WhereParameter.Dir.ASC);
                        pol.Query.Load();
                        uiDropDownListMachineCivil.DataSource = pol.DefaultView;
                        uiDropDownListMachineCivil.DataTextField = POLICE_STATION.ColumnNames.DESCR;
                        uiDropDownListMachineCivil.DataValueField = POLICE_STATION.ColumnNames.CD;
                        uiDropDownListMachineCivil.DataBind();
                        uiDropDownListMachineCivil.Items.Insert(0, new ListItem("---", "0"));
                        uiDropDownListMachineCivil.SelectedIndex = 0;
                    }

                    if (Current.CivilId != 0)
                    {
                        uiDropDownListCivil.SelectedValue = Current.CivilId.ToString();
                        uiDropDownListCivil.Enabled = false;
                        uiDropDownListMachineCivil.SelectedValue = Current.CivilId.ToString();
                        uiDropDownListMachineCivil.Enabled = false;

                        if (uiDropDownListCivil.SelectedIndex != 0 && uiDropDownListGov.SelectedIndex != 0)
                        {
                            health_office obj = new health_office();
                            uiDropDownListHealthOffice.DataSource = obj.GetHealthOfficeDetails(short.Parse(uiDropDownListGov.SelectedValue), short.Parse(uiDropDownListCivil.SelectedValue)).DefaultView;
                            uiDropDownListHealthOffice.DataTextField = health_office.ColumnNames.HEALTHDESCR;
                            uiDropDownListHealthOffice.DataValueField = health_office.ColumnNames.HEALTHCD;
                            uiDropDownListHealthOffice.DataBind();
                            uiDropDownListHealthOffice.Items.Insert(0, new ListItem("---", "0"));
                            uiDropDownListHealthOffice.SelectedIndex = 0;
                        }

                        if (uiDropDownListMachineGov.SelectedIndex != 0 && uiDropDownListMachineCivil.SelectedIndex != 0)
                        {
                            health_office obj = new health_office();
                            uiDropDownListMachineHealthOffice.DataSource = obj.GetHealthOfficeDetails(short.Parse(uiDropDownListMachineGov.SelectedValue), short.Parse(uiDropDownListMachineCivil.SelectedValue)).DefaultView;
                            uiDropDownListMachineHealthOffice.DataTextField = health_office.ColumnNames.HEALTHDESCR;
                            uiDropDownListMachineHealthOffice.DataValueField = health_office.ColumnNames.HEALTHCD;
                            uiDropDownListMachineHealthOffice.DataBind();
                            uiDropDownListMachineHealthOffice.Items.Insert(0, new ListItem("---", "0"));
                            uiDropDownListMachineHealthOffice.SelectedIndex = 0;
                        }
                    }
                }
                /************************/
            }
        }
        catch (Exception)
        {
            // gives error when log out
        }
    }
    private void LoadLookups()
    {
        GOVERNORATE gov = new GOVERNORATE();
        gov.LoadAll();

        uiDropDownListGov.DataSource = gov.DefaultView;
        uiDropDownListGov.DataTextField = GOVERNORATE.ColumnNames.DESCR;
        uiDropDownListGov.DataValueField = GOVERNORATE.ColumnNames.CD;
        uiDropDownListGov.DataBind();
        uiDropDownListGov.Items.Insert(0, new ListItem("---", "0"));
        uiDropDownListGov.SelectedValue = MHOCommon.CurrentOrgGovID.ToString();

        if (uiDropDownListGov.SelectedIndex != 0)
        {
            CIVIL_OFFICE pol = new CIVIL_OFFICE();
            pol.Where.FK_GOVCD.Value = short.Parse(uiDropDownListGov.SelectedValue);
            pol.Where.FK_GOVCD.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
            pol.Query.AddOrderBy(CIVIL_OFFICE.ColumnNames.DESCR, MyGeneration.dOOdads.WhereParameter.Dir.ASC);
            pol.Query.Load();
            uiDropDownListCivil.DataSource = pol.DefaultView;
            uiDropDownListCivil.DataTextField = POLICE_STATION.ColumnNames.DESCR;
            uiDropDownListCivil.DataValueField = POLICE_STATION.ColumnNames.CD;
            uiDropDownListCivil.DataBind();
            uiDropDownListCivil.Items.Insert(0, new ListItem("---", "0"));
            uiDropDownListCivil.SelectedIndex = 0;
        }

        uiDropDownListMachineGov.DataSource = gov.DefaultView;
        uiDropDownListMachineGov.DataTextField = GOVERNORATE.ColumnNames.DESCR;
        uiDropDownListMachineGov.DataValueField = GOVERNORATE.ColumnNames.CD;
        uiDropDownListMachineGov.DataBind();
        uiDropDownListMachineGov.Items.Insert(0, new ListItem("---", "0"));
        uiDropDownListMachineGov.SelectedIndex = 0;
    }
 private void Filter()
 {
     CIVIL_OFFICE obj = new CIVIL_OFFICE();
     obj.Where.FK_GOVCD.Value = short.Parse(drpGove.SelectedValue);
     obj.Where.FK_GOVCD.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
     obj.Query.AddOrderBy(CIVIL_OFFICE.ColumnNames.DESCR, MyGeneration.dOOdads.WhereParameter.Dir.ASC);
     obj.Query.Load();
     grdGovernate.DataSource = obj.DefaultView;
     grdGovernate.DataBind();
 }
 private void LoadCivilOffice()
 {
     CIVIL_OFFICE pol = new CIVIL_OFFICE();
     pol.Where.FK_GOVCD.Value = short.Parse(drpGove.SelectedValue);
     pol.Where.FK_GOVCD.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
     pol.Query.AddOrderBy(CIVIL_OFFICE.ColumnNames.DESCR, MyGeneration.dOOdads.WhereParameter.Dir.ASC);
     pol.Query.Load();
     drpCivilOffice.DataSource = pol.DefaultView;
     drpCivilOffice.DataTextField = POLICE_STATION.ColumnNames.DESCR;
     drpCivilOffice.DataValueField = POLICE_STATION.ColumnNames.CD;
     drpCivilOffice.DataBind();
 }