private void btn_Delete_Click_1(object sender, RoutedEventArgs e)
 {
     if (grd_Company.SelectedItem != null)
     {
         company = (Company)grd_Company.SelectedItem;
         MessageBoxResult result = MessageBox.Show("هل انت متأكد من حذف " + company.Name, "حذف الشركة", MessageBoxButton.YesNo, MessageBoxImage.Question);
         if (result == MessageBoxResult.Yes)
         {
             companyDomain.Delete(company);
             if (companyDomain.ActionState.Status == Common.Enums.ActionStatusEnum.NoError)
             {
                 MessageBox.Show("تم الحذف بنجاح", "حذف الشركة", MessageBoxButton.OK, MessageBoxImage.Information);
                 companyList.Remove(company);
                 grd_Company.ItemsSource = null;
                 grd_Company.ItemsSource = companyList;
                 Clear();
             }
             else
             {
                 MessageBox.Show(companyDomain.ActionState.Result, "حذف الشركة", MessageBoxButton.OK, MessageBoxImage.Error);
                 Clear();
             }
         }
     }
 }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            company = domain.FindByID(CompanyID);
            string[] cap = company.Capital.ToString("C", CultureInfo.CreateSpecificCulture("ar-SA")).Split(' ');
            txt_CompanyCapital.Text = cap[1]+ " "+cap[0];
            txt_CompanyDesc.Text = company.Description;
            string[] date = GerToHejri(company.EstablishYear.ToString("dd/MM/yyyy")).Split('/');
            txt_CompanyEstablish.Text = date[2] + "/" + date[1] + "/" + date[0];
            txt_CompanyName.Text = company.Name;
            txt_CompanySec.Text = company.Sector.Name;
            //foreach (Behaviour behaviour in company.BehaviourList)
            //{
            //    SectorDetailSectionReport sectorDetailSectionReport = new SectorDetailSectionReport(behaviour.Name, behaviour.Description);
            //    stk_BehaviourDetails.Children.Add(sectorDetailSectionReport);
            //}

            foreach (SisterCompany sister in company.SisterCompanyList)
            {
                SisterCompanyDetailSectionReport sisterCompanyDetailSectionReport = new SisterCompanyDetailSectionReport(sister.Name, sister.Sector.Name, sister.OwnerPercentage.ToString());
                stk_SisterCompany.Children.Add(sisterCompanyDetailSectionReport);
            }

            foreach (SubsidiaryCompany subsidiary in company.SubsidiaryCompanyList)
            {
                SisterCompanyDetailSectionReport sisterCompanyDetailSectionReport = new SisterCompanyDetailSectionReport(subsidiary.Name, subsidiary.Sector.Name, subsidiary.OwnPercentage.ToString());
                stk_SubCompany.Children.Add(sisterCompanyDetailSectionReport);
            }
        }
        private void grd_Sector_MouseDoubleClick_1(object sender, MouseButtonEventArgs e)
        {
            Clear();
            if (grd_Company.SelectedItem != null)
            {
                company = (Company)grd_Company.SelectedItem;
                txt_Capital.Value =Convert.ToDecimal( company.Capital);
                txt_Description.Text = company.Description;
                txt_DescriptionEnglish.Text = company.DescriptionEnglish;
                txt_Information.Text = company.Information;
                txt_InformationEnglish.Text = company.InformationEnglish;
                txt_Name.Text = company.Name;
                txt_NameEnglish.Text = company.NameEnglish;
                txt_Rank.Text = company.Rank.ToString();
                txt_Behavior.Text = company.Behavior;
                for (int i = 0; i < cmbo_Sector.Items.Count; i++)
                {
                    if (company.Sector.ID == ((Sector)cmbo_Sector.Items[i]).ID)
                    {
                        cmbo_Sector.SelectedIndex = i;
                        break;
                    }
                }

                if (company.EstablishYear.Year != 1)
                {
                    dtpkr_EstablishGer.Text = company.EstablishYear.Date.ToString("dd/MM/yyyy");
                    dtpkr_EstablishHij.Text = GerToHejri(dtpkr_EstablishGer.Text);
                }

                if (company.WithLimitedLiability.Year != 1)
                {
                    dtpkr_WithLimitedLiability_Ger.Text = company.WithLimitedLiability.Date.ToString("dd/MM/yyyy");
                    dtpkr_WithLimitedLiability_Hijri.Text = GerToHejri(dtpkr_WithLimitedLiability_Ger.Text);
                }

                if (company.ClosedJointStockCompany.Year != 1)
                {
                    dtpkr_ClosedJointStockCompany_Ger.Text = company.ClosedJointStockCompany.Date.ToString("dd/MM/yyyy");
                    dtpkr_ClosedJointStockCompany_Hijri.Text = GerToHejri(dtpkr_ClosedJointStockCompany_Ger.Text);
                }

                if (company.IPO.Year != 1)
                {
                    dtpkr_IPO_Ger.Text = company.IPO.Date.ToString("dd/MM/yyyy");
                    dtpkr_IPO_Hijri.Text = GerToHejri(dtpkr_IPO_Ger.Text);
                }

                if (company.GeneralCompany.Year != 1)
                {
                    dtpkr_GeneralCompany_Ger.Text = company.GeneralCompany.Date.ToString("dd/MM/yyyy");
                    dtpkr_GeneralCompany_Hijri.Text = GerToHejri(dtpkr_GeneralCompany_Ger.Text);
                }

                stk_SubCompanies.Visibility = System.Windows.Visibility.Visible;
                //for (int i = 0; i < company.BehaviourList.Count; i++)
                //{
                //    for (int j = 0; j < cmbo_Behaviours.Items.Count; j++)
                //    {
                //        if (((Behaviour)((CheckBox)cmbo_Behaviours.Items[j]).DataContext).ID == company.BehaviourList[i].ID)
                //        {
                //            ((CheckBox)cmbo_Behaviours.Items[j]).IsChecked = true;
                //        }
                //    }
                //}
            }
        }
        private void Clear()
        {
            txt_Capital.Text = string.Empty;
            txt_Behavior.Text = string.Empty;
            txt_Description.Text = string.Empty;
            txt_DescriptionEnglish.Text = string.Empty;
            txt_Err_Capital.Text = string.Empty;
            txt_Err_ClosedJointStockCompany.Text = string.Empty;
            txt_Err_Description.Text = string.Empty;
            txt_Err_DescriptionEnglish.Text = string.Empty;
            txt_Err_Establish.Text = string.Empty;
            txt_Err_GeneralCompany.Text = string.Empty;
            txt_Err_Information.Text = string.Empty;
            txt_Err_InformationEnglish.Text = string.Empty;
            txt_Err_IPO.Text = string.Empty;
            txt_Err_Name.Text = string.Empty;
            txt_Err_NameEnglish.Text = string.Empty;
            txt_Err_WithLimitedLiability.Text = string.Empty;
            txt_Information.Text = string.Empty;
            txt_InformationEnglish.Text = string.Empty;
            txt_Name.Text = string.Empty;
            txt_NameEnglish.Text = string.Empty;
            txt_Err_Behavior.Text = string.Empty;

            dtpkr_ClosedJointStockCompany_Ger.Text = string.Empty;
            dtpkr_ClosedJointStockCompany_Hijri.Text = string.Empty;
            dtpkr_EstablishGer.Text = string.Empty;
            dtpkr_EstablishHij.Text = string.Empty;
            dtpkr_GeneralCompany_Ger.Text = string.Empty;
            dtpkr_GeneralCompany_Hijri.Text = string.Empty;
            dtpkr_IPO_Ger.Text = string.Empty;
            dtpkr_IPO_Hijri.Text = string.Empty;
            dtpkr_WithLimitedLiability_Ger.Text = string.Empty;
            dtpkr_WithLimitedLiability_Hijri.Text = string.Empty;
            txt_Err_Rank.Text = string.Empty;
            txt_Rank.Text = string.Empty;
            company = new Company();
            cmbo_Sector.SelectedIndex = 0;
            //grd_Company.ItemsSource = companyDomain.FindAll();
            stk_SubCompanies.Visibility = System.Windows.Visibility.Collapsed;
            //for (int i = 0; i < cmbo_Behaviours.Items.Count; i++)
            //{
            //    ((CheckBox)cmbo_Behaviours.Items[i]).IsChecked = false;
            //}
        }