/// <summary>
 /// Form Load
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void formMDI_Load(object sender, EventArgs e)
 {
     try
     {
         CheckNewVersionComesOfOpenMiracle();
         MDIObj = this;
         MenuStripDisabling();
         companyToolStripMenuItem.Enabled = true;
         editCompanyToolStripMenuItem1.Enabled = false;
         BackUpToolStripMenuItem.Enabled = false;
         RestoreToolStripMenuItem.Enabled = false;
         dateToolStripMenuItem.Enabled = false;
         exitToolStripMenuItem.Enabled = true;
         createCompanyToolStripMenuItem.Enabled = true;
         SelectCompanyToolStripMenuItem.Enabled = true;
         logoutToolStripMenuItem.Enabled = false;
         logoutToolStripMenuItem.Enabled = false;
         //CompanySP spCompany = new CompanySP();
         CompanyCreationBll bllCompanyCreation = new CompanyCreationBll();
         decimal decCompanyCount = bllCompanyCreation.CompanyCount();
         if (decCompanyCount != -1)
         {
             if (decCompanyCount == 1)
             {
                 PublicVariables._decCurrentCompanyId = bllCompanyCreation.CompanyGetIdIfSingleCompany();
                 CurrentDate();
                 frmLogin frmLoginObj = new frmLogin();
                 frmLoginObj.MdiParent = MDIObj;
                 frmLoginObj.CallFromFormMdi(this);
             }
             else if (decCompanyCount < 1)
             {
                 CurrentDateBefore();
                 frmCompanyCreation frmCompanyCreationObj = new frmCompanyCreation();
                 frmCompanyCreationObj.MdiParent = formMDI.MDIObj;
                 frmCompanyCreationObj.CallFromFormMdi();
                 SelectCompanyToolStripMenuItem.Enabled = false;
             }
             else
             {
                 PublicVariables._decCurrentCompanyId = 0;
                 //CompanyPathSP spCompanyPath = new CompanyPathSP();
                 CompanyPathBll bllCompanyPath = new CompanyPathBll();
                 decimal decDefaultCompanyId = bllCompanyPath.CompanyViewForDefaultCompany();
                 if (decDefaultCompanyId > 0)
                 {
                     PublicVariables._decCurrentCompanyId = decDefaultCompanyId;
                     CurrentDate();
                     frmLogin frmLoginObj = new frmLogin();
                     frmLoginObj.MdiParent = formMDI.MDIObj;
                     frmLoginObj.CallFromFormMdi(this);
                 }
                 else
                 {
                     CurrentDate();
                     frmSelectCompany frmSelectCompanyObj = new frmSelectCompany();
                     frmSelectCompanyObj.MdiParent = formMDI.MDIObj;
                     frmSelectCompanyObj.CallFromMdi();
                 }
             }
             CurrentSettings();
         }
         else
         {
             createCompanyToolStripMenuItem.Enabled = false;
             SelectCompanyToolStripMenuItem.Enabled = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MDI 40 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Disables the menus and Logouts company
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void logoutToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     try
     {
         List<Form> openForms = new List<Form>();
         foreach (Form f in Application.OpenForms)
             openForms.Add(f);
         foreach (Form f in openForms)
         {
             if (f.Name != "formMDI")
                 f.Close();
         }
         MDIObj = this;
         PublicVariables._decCurrentCompanyId = 0;
         MenuStripDisabling();
         companyToolStripMenuItem.Enabled = true;
         editCompanyToolStripMenuItem1.Enabled = false;
         BackUpToolStripMenuItem.Enabled = false;
         RestoreToolStripMenuItem.Enabled = false;
         dateToolStripMenuItem.Enabled = false;
         exitToolStripMenuItem.Enabled = true;
         createCompanyToolStripMenuItem.Enabled = true;
         SelectCompanyToolStripMenuItem.Enabled = true;
         logoutToolStripMenuItem.Enabled = false;
         formMDI.MDIObj.Text = "OpenMiracle";
         //CompanySP spCompany = new CompanySP();
         CompanyCreationBll bllCompanyCreation = new CompanyCreationBll();
         decimal decCompanyCount = bllCompanyCreation.CompanyCount();
         if (decCompanyCount == 1)
         {
             PublicVariables._decCurrentCompanyId = bllCompanyCreation.CompanyGetIdIfSingleCompany();
             CurrentDate();
             frmLogin frmLoginObj = new frmLogin();
             frmLoginObj.MdiParent = MDIObj;
             frmLoginObj.CallFromFormMdi(this);
         }
         else if (decCompanyCount < 1)
         {
             CurrentDateBefore();
             frmCompanyCreation frmCompanyCreationObj = new frmCompanyCreation();
             frmCompanyCreationObj.MdiParent = formMDI.MDIObj;
             frmCompanyCreationObj.CallFromFormMdi();
         }
         else
         {
             PublicVariables._decCurrentCompanyId = 0;
             //CompanyPathSP spCompanyPath = new CompanyPathSP();
             CompanyPathBll bllCompanyPath = new CompanyPathBll();
             decimal decDefaultCompanyId = bllCompanyPath.CompanyViewForDefaultCompany();
             if (decDefaultCompanyId > 0)
             {
                 PublicVariables._decCurrentCompanyId = decDefaultCompanyId;
                 CurrentDate();
                 frmLogin frmLoginObj = new frmLogin();
                 frmLoginObj.MdiParent = formMDI.MDIObj;
                 frmLoginObj.CallFromFormMdi(this);
             }
             else
             {
                 CurrentDate();
                 frmSelectCompany frmSelectCompanyObj = new frmSelectCompany();
                 frmSelectCompanyObj.MdiParent = formMDI.MDIObj;
                 frmSelectCompanyObj.CallFromMdi();
             }
         }
         CurrentSettings();
     }
     catch (Exception ex)
     {
         MessageBox.Show("MDI 214: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function for Save
 /// </summary>
 public void SaveFunction()
 {
     try
     {
         CompanyInfo infoCompany = new CompanyInfo();
         CompanyCreationBll BllCompanyCreation = new CompanyCreationBll();
         CompanyPathInfo infoCompanyPath = new CompanyPathInfo();
         CompanyPathBll BllCompanyPath = new CompanyPathBll();
         UserInfo infoUser = new UserInfo();
         UserBll bllUser = new UserBll();
         ExchangeRateInfo infoExchangeRate = new ExchangeRateInfo();
         //ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
         infoCompany.CompanyName = txtCompanyName.Text.Trim();
         infoCompany.MailingName = txtMailingName.Text.Trim();
         infoCompany.Address = txtAddress.Text.Trim();
         infoCompany.Phone = txtPhoneNo.Text.Trim();
         infoCompany.Mobile = txtMobile.Text.Trim();
         infoCompany.EmailId = txtEmail.Text.Trim();
         infoCompany.Web = txtWeb.Text.Trim();
         infoCompany.Country = txtCountry.Text.Trim();
         infoCompany.State = txtState.Text.Trim();
         infoCompany.Pin = txtPincode.Text.Trim();
         infoCompany.CurrencyId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         decCurrencyIdForStatus = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         infoCompany.FinancialYearFrom = Convert.ToDateTime(txtFinancialYearFrom.Text.Trim().ToString());
         infoCompany.BooksBeginingFrom = Convert.ToDateTime(txtBooksBegining.Text.Trim().ToString());
         infoCompany.Tin = txtTinNo.Text.Trim();
         infoCompany.Cst = txtCstNo.Text.Trim();
         infoCompany.Pan = txtPanNo.Text.Trim();
         infoCompany.CurrentDate = DateTime.Now;
         infoCompany.Logo = logo;
         infoCompany.Extra1 = string.Empty;
         infoCompany.Extra2 = string.Empty;
         infoCompanyPath.CompanyName = txtCompanyName.Text.Trim();
         infoCompanyPath.IsDefault = cbxSetAsDefault.Checked;
         infoCompanyPath.Extra1 = string.Empty;
         infoCompanyPath.Extra2 = string.Empty;
         infoUser.UserName = txtAdminUserName.Text.Trim();
         infoUser.Password = txtPassword.Text.Trim();
         infoUser.Active = true;
         infoUser.Extra1 = string.Empty;
         infoUser.Extra2 = string.Empty;
         infoUser.Narration = string.Empty;
         infoUser.RoleId = 1;
         if (BllCompanyCreation.CompanyCheckExistence(txtCompanyName.Text.Trim().ToString(), 0) == false)
         {
             decimal decCompanyId = BllCompanyCreation.CompanyAddParticularFeilds(infoCompany);
             PublicVariables._decCurrentCompanyId = decCompanyId;
             infoCompanyPath.CompanyPath = Application.StartupPath + "\\Data\\" + PublicVariables._decCurrentCompanyId;
             BllCompanyPath.CompanyPathAdd(infoCompanyPath);
             if (formMDI.demoProject || CreateCompany())
             {
                 if (!formMDI.demoProject)
                 {
                     infoCompanyPath.CompanyPath = strPath;
                 }
                 else
                 {
                     infoCompanyPath.CompanyPath = Application.StartupPath + "\\Data";
                     PublicVariables._decCurrentCompanyId = 0;
                 }
                 CompanyInfo infoNewCompany = new CompanyInfo();
                 CompanyPathInfo infoNewCompanyPath = new CompanyPathInfo();
                 UserInfo infoNewUser = new UserInfo();
                 UserBll bllNewUser = new UserBll();
                 ExchangeRateInfo infoNewExchangeRate = new ExchangeRateInfo();
                 ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
                 CompanyPathBll BllNewCompanyPath = new CompanyPathBll();
                 infoNewCompany = infoCompany;
                 infoNewCompanyPath = infoCompanyPath;
                 infoNewUser = infoUser;
                 decCompanyId = BllCompanyCreation.CompanyAddParticularFeilds(infoNewCompany);
                 bllNewUser.UserAdd(infoNewUser);
                 BllNewCompanyPath.CompanyPathAdd(infoNewCompanyPath);
                 Messages.SavedMessage();
                 formMDI.MDIObj.MenuStripEnabling();
                 //  To set default currencyId.............//
                 infoNewExchangeRate.CurrencyId = infoNewCompany.CurrencyId;
                 infoNewExchangeRate.Rate = 1;
                 infoNewExchangeRate.Narration = string.Empty;
                 infoNewExchangeRate.Extra1 = string.Empty;
                 infoNewExchangeRate.Extra2 = string.Empty;
                 infoNewExchangeRate.ExtraDate = System.DateTime.Now;
                 infoNewExchangeRate.Date = System.DateTime.Now;
                 BllExchangeRate.ExchangeRateAdd(infoNewExchangeRate);
                 CurrencyBll BllCurrency = new CurrencyBll();
                 BllCurrency.DefaultCurrencySet(decCurrencyIdForStatus);
                 AfterCompanyCreation();
                 Clear();
                 this.Close();
             }
             else
             {
                 Messages.InformationMessage("Company creation failed");
             }
         }
         else
         {
             Messages.InformationMessage("Companyname already exist");
             txtCompanyName.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("CR1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function for Edit
 /// </summary>
 public void EditFunction()
 {
     try
     {
         CompanyInfo infoCompany = new CompanyInfo();
         CompanyCreationBll BllCompanyCreation = new CompanyCreationBll();
         CompanyPathInfo infoCompanyPath = new CompanyPathInfo();
         CompanyPathBll BllCompanyPath = new CompanyPathBll();
         UserInfo infoUser = new UserInfo();
         UserBll bllUser = new UserBll();
         infoCompany.CompanyName = txtCompanyName.Text.Trim();
         infoCompany.MailingName = txtMailingName.Text.Trim();
         infoCompany.Address = txtAddress.Text.Trim();
         infoCompany.Phone = txtPhoneNo.Text.Trim();
         infoCompany.Mobile = txtMobile.Text.Trim();
         infoCompany.EmailId = txtEmail.Text.Trim();
         infoCompany.Web = txtWeb.Text.Trim();
         infoCompany.Country = txtCountry.Text.Trim();
         infoCompany.State = txtState.Text.Trim();
         infoCompany.Pin = txtPincode.Text.Trim();
         infoCompany.CurrencyId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         infoCompany.FinancialYearFrom = Convert.ToDateTime(txtFinancialYearFrom.Text.Trim().ToString());
         infoCompany.BooksBeginingFrom = Convert.ToDateTime(txtBooksBegining.Text.Trim().ToString());
         infoCompany.Tin = txtTinNo.Text.Trim();
         infoCompany.Cst = txtCstNo.Text.Trim();
         infoCompany.Pan = txtPanNo.Text.Trim();
         infoCompany.CurrentDate = DateTime.Now;
         infoCompany.Logo = logo;
         infoCompany.Extra1 = string.Empty;
         infoCompany.Extra2 = string.Empty;
         infoCompanyPath.CompanyName = txtCompanyName.Text.Trim();
         infoCompanyPath.IsDefault = cbxSetAsDefault.Checked;
         strPath = Application.StartupPath + "\\Data\\" + PublicVariables._decCurrentCompanyId;
         infoCompanyPath.CompanyPath = strPath;
         infoCompanyPath.Extra1 = string.Empty;
         infoCompanyPath.Extra2 = string.Empty;
         infoCompanyPath.ExtraDate = DateTime.Now;
         infoCompanyPath.CompanyId = 1;
         infoCompany.CompanyId = 1;
         BllCompanyCreation.CompanyEdit(infoCompany);
         BllCompanyPath.CompanyPathEdit(infoCompanyPath);
         Messages.UpdatedMessage();
         //  To set default currencyId...........In exchangeRate..//
         ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
         ExchangeRateInfo infoExchangeRate = new ExchangeRateInfo();
         infoExchangeRate.ExchangeRateId = 1;
         infoExchangeRate.Date = PublicVariables._dtCurrentDate;
         infoExchangeRate.CurrencyId = infoCompany.CurrencyId;
         infoExchangeRate.ExtraDate = PublicVariables._dtCurrentDate;
         infoExchangeRate.Narration = string.Empty;
         infoExchangeRate.Rate = 1;
         infoExchangeRate.Extra1 = string.Empty;
         infoExchangeRate.Extra2 = string.Empty;
         BllExchangeRate.ExchangeRateEdit(infoExchangeRate);
         FinancialYearInfo infoFinancialYear = new FinancialYearInfo();
         FinancialYearBll BllFinancialYear = new FinancialYearBll();
         decimal decIdentity;
         infoFinancialYear.FromDate = PublicVariables._dtFromDate;
         infoFinancialYear.ToDate = PublicVariables._dtToDate;
         infoFinancialYear.ExtraDate = DateTime.Now;
         infoFinancialYear.Extra1 = string.Empty;
         infoFinancialYear.Extra2 = string.Empty;
         bool isExist = BllFinancialYear.FinancialYearExistenceCheck(PublicVariables._dtFromDate, PublicVariables._dtToDate);
         if (!isExist)
         {
             decIdentity = BllFinancialYear.FinancialYearAddWithReturnIdentity(infoFinancialYear);
         }
         //===========Add companyDetails in ExternalDb =====================//
         decimal decCompanyIdForTemp = PublicVariables._decCurrentCompanyId;
         PublicVariables._decCurrentCompanyId = 0;
         CompanyCreationBll bllExCompanyCreation = new CompanyCreationBll();
         CompanyPathBll bllExCompanyPath = new CompanyPathBll();
         CompanyInfo infoExCompany = new CompanyInfo();
         CompanyPathInfo infoExCompanyPath = new CompanyPathInfo();
         infoExCompany = infoCompany;
         infoExCompanyPath = infoCompanyPath;
         infoExCompany.CompanyId = decCompanyIdForTemp;
         infoExCompanyPath.CompanyId = decCompanyIdForTemp;
         bllExCompanyCreation.CompanyEdit(infoExCompany);
         bllExCompanyPath.CompanyPathEdit(infoExCompanyPath);
         PublicVariables._decCurrentCompanyId = decCompanyIdForTemp;
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("CR2:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to delete a company
 /// </summary>
 public void DeleteFunction()
 {
     try
     {
         decimal decCompanyIdForTemp = PublicVariables._decCurrentCompanyId;
         CompanyCreationBll BllCompanyCreation = new CompanyCreationBll();
         PublicVariables._decCurrentCompanyId = 0;
         CompanyCreationBll bllExCompanyCreation = new CompanyCreationBll();
         CompanyPathBll bllExCompanyPath = new CompanyPathBll();
         bllExCompanyCreation.CompanyDelete(decCompanyIdForTemp);
         bllExCompanyPath.CompanyPathDelete(decCompanyIdForTemp);
         Messages.DeletedMessage();
         Application.Restart();
     }
     catch (Exception ex)
     {
         MessageBox.Show("CR12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill controls for Update
 /// </summary>
 public void CompanyViewForEdit()
 {
     try
     {
         isEditMode = true;
         this.Text = "Edit Company";
         btnSave.Text = "Update";
         btnDelete.Enabled = true;
         gbxDetails.Visible = false;
         txtAdminUserName.ReadOnly = true;
         txtAdminUserName.BackColor = Color.White;
         cmbCurrency.Enabled = false;
         CompanyCreationBll BllCompanyCreation = new CompanyCreationBll();
         CompanyInfo infoCompany = new CompanyInfo();
         decimal decCompanyId = 1;
         infoCompany = BllCompanyCreation.CompanyView(PublicVariables._decCurrentCompanyId);
         txtCompanyName.Text = infoCompany.CompanyName;
         txtMailingName.Text = infoCompany.MailingName;
         txtAddress.Text = infoCompany.Address;
         txtPhoneNo.Text = infoCompany.Phone;
         txtMobile.Text = infoCompany.Mobile;
         txtEmail.Text = infoCompany.EmailId;
         txtWeb.Text = infoCompany.Web;
         txtCountry.Text = infoCompany.Country;
         txtState.Text = infoCompany.State;
         txtPincode.Text = infoCompany.Pin;
         cmbCurrency.SelectedValue = infoCompany.CurrencyId;
         txtFinancialYearFrom.Text = infoCompany.FinancialYearFrom.ToString("dd-MMM-yyyy");
         dtpFinancialYearFrom.Text = infoCompany.FinancialYearFrom.ToString();
         txtBooksBegining.Text = infoCompany.BooksBeginingFrom.ToString("dd-MMM-yyyy");
         dtpBooksBegining.Text = infoCompany.BooksBeginingFrom.ToString();
         txtTinNo.Text = infoCompany.Tin;
         txtCstNo.Text = infoCompany.Cst;
         txtPanNo.Text = infoCompany.Pan;
         logo = (byte[])infoCompany.Logo;
         MemoryStream ms = new MemoryStream(logo);
         Image newimage = Image.FromStream(ms);
         pbxLogo.Image = newimage;
         pbxLogo.SizeMode = PictureBoxSizeMode.StretchImage;
         CompanyPathInfo infoCompanyPath = new CompanyPathInfo();
         CompanyPathBll BllComapnyPath = new CompanyPathBll();
         infoCompanyPath = BllComapnyPath.CompanyPathView(1);
         if (infoCompanyPath.IsDefault == true)
         {
             cbxSetAsDefault.Checked = true;
         }
         else
         {
             cbxSetAsDefault.Checked = false;
         }
         UserBll bllUser = new UserBll();
         UserInfo infoUser = new UserInfo();
         decimal decuserId = PublicVariables._decCurrentUserId;
         infoUser = bllUser.UserView(decuserId);
         txtAdminUserName.Text = infoUser.UserName;
         txtPassword.Text = infoUser.Password;
         txtRetypePassword.Text = infoUser.Password;
     }
     catch (Exception ex)
     {
         MessageBox.Show("CR8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill company path
 /// </summary>
 public void FillDBS()
 {
     decimal decCompanyId = PublicVariables._decCurrentCompanyId;
     PublicVariables._decCurrentCompanyId = 0;
     //CompanyPathSP spCompanyPath = new CompanyPathSP();
     CompanyPathBll bllCompanyPath = new CompanyPathBll();
     List<DataTable> listObj = new List<DataTable>();
     try
     {
         listObj = bllCompanyPath.CompanyPathViewAll();
     DataRow dr = listObj[0].NewRow();
     dr["companyPath"] = Application.StartupPath + "\\Data\\COMP";
     dr["companyId"] = -1;
     listObj[0].Rows.InsertAt(dr, 0);
     cbUpdation.BindingContext = new BindingContext();
     cbUpdation.DataSource = listObj[0];
     cbUpdation.DisplayMember = "companyPath";
     cbUpdation.ValueMember = "companyId";
     for (int i = 0; i < cbUpdation.Items.Count; ++i)
         cbUpdation.SetItemChecked(i, true);
     PublicVariables._decCurrentCompanyId = decCompanyId;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SPIns:1" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }