private void btnCancel_Click(object sender, EventArgs e)
        {
            BPrincipalCompany.EnableToEdit(objPrincipalCompany.prco_uuid__uniqueidentifier);

            objPrincipalCompany = BPrincipalCompany.FindByUUID(objPrincipalCompany.prco_uuid__uniqueidentifier);

            txtRFC.Enabled           = false;
            txtCompany.Enabled       = false;
            txtAddress.Enabled       = false;
            txtPhone.Enabled         = false;
            txtEmail.Enabled         = false;
            txtFacebook.Enabled      = false;
            cboState.Enabled         = false;
            cboCity.Enabled          = false;
            pcbLogo.Enabled          = false;
            cboMode.Enabled          = false;
            nudHoursToBackup.Enabled = false;
            nudHoursToBackup.Enabled = false;

            txtRFC.Text      = objPrincipalCompany.prco_rfc__nvarchar;
            txtCompany.Text  = objPrincipalCompany.prco_name__nvarchar;
            txtAddress.Text  = objPrincipalCompany.prco_address__nvarchar;
            txtPhone.Text    = objPrincipalCompany.prco_phone__nvarchar;
            txtEmail.Text    = objPrincipalCompany.prco_email__nvarchar;
            txtFacebook.Text = objPrincipalCompany.prco_facebook__nvarchar;

            cboState.Items.Clear();
            cboCity.Items.Clear();

            RefreshStates();

            if (objPrincipalCompany.city_uuid__uniqueidentifier != null)
            {
                var vCity = BCity.FindByUUID(objPrincipalCompany.city_uuid__uniqueidentifier.Value);

                cboState.Text = BState.FindByUUID(vCity.stat_uuid__uniqueidentifier).stat_name__nvarchar;

                cboCity.Text = vCity.city_name__nvarchar;

                RefreshCities();
            }

            pcbLogo.Image = objPrincipalCompany.reso_uuid_logo__uniqueidentifier != null?Tools.ConvertirByteAImagen(BResource.FindByUUID(objPrincipalCompany.reso_uuid_logo__uniqueidentifier.Value).reso_value__varbinary) : null;

            cboMode.SelectedIndex  = objPrincipalCompany.prco_developmentmode__bit == true ? 0 : 1;
            nudHoursToBackup.Value = objPrincipalCompany.prco_hoursbetweenbackups__int;
            nudDaysToDelete.Value  = objPrincipalCompany.prco_daysdeletbackups__int;

            btnAccept.Visible = btnCancel.Visible = false;
            btnEdit.Visible   = true;

            btnClose.Enabled = true;

            btnEdit.Focus();

            byAction = 0;
        }
        public static bool DisableToEdit(Guid objGuid, session objSession)
        {
            try
            {
                using (ModelContext objContext = new ModelContext())
                {
                    principalcompany objPrincipalCompany = objContext.principalcompanies.Where(p => p.prco_uuid__uniqueidentifier == objGuid).FirstOrDefault();

                    if (objPrincipalCompany != null)
                    {
                        objPrincipalCompany.sess_uuid_used__uniqueidentifier = objSession.sess_uuid__uniqueidentifier;
                        objContext.SaveChanges();
                    }
                }
            }
            catch { }

            return(false);
        }
        public static bool EnableToEdit(Guid objGuid)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    principalcompany objPrincipalCompany = objContext.principalcompanies.Where(p => p.prco_uuid__uniqueidentifier == objGuid).FirstOrDefault();

                    if (objPrincipalCompany != null)
                    {
                        objPrincipalCompany.sess_uuid_used__uniqueidentifier = null;
                        objContext.SaveChanges();

                        return(true);
                    }
                }
            }
            catch { }

            return(false);
        }
        public void RefreshMainValues()
        {
            objPrincipalCompany = null;

            var vPrincipalCompany = BPrincipalCompany.Get();

            if (vPrincipalCompany != null)
            {
                objPrincipalCompany = vPrincipalCompany;

                RefreshStates();
                RefreshModes();

                txtRFC.Text      = vPrincipalCompany.prco_rfc__nvarchar;
                txtCompany.Text  = vPrincipalCompany.prco_name__nvarchar;
                txtAddress.Text  = vPrincipalCompany.prco_address__nvarchar;
                txtPhone.Text    = vPrincipalCompany.prco_phone__nvarchar;
                txtEmail.Text    = vPrincipalCompany.prco_email__nvarchar;
                txtFacebook.Text = vPrincipalCompany.prco_facebook__nvarchar;

                if (vPrincipalCompany.city_uuid__uniqueidentifier != null)
                {
                    var vCity = BCity.FindByUUID(vPrincipalCompany.city_uuid__uniqueidentifier.Value);

                    cboState.Text = BState.FindByUUID(vCity.stat_uuid__uniqueidentifier).stat_name__nvarchar;

                    cboCity.Text = vCity.city_name__nvarchar;

                    RefreshCities();
                }

                pcbLogo.Image = vPrincipalCompany.reso_uuid_logo__uniqueidentifier != null?Tools.ConvertirByteAImagen(BResource.FindByUUID(vPrincipalCompany.reso_uuid_logo__uniqueidentifier.Value).reso_value__varbinary) : null;

                cboMode.SelectedIndex  = vPrincipalCompany.prco_developmentmode__bit ? 0 : 1;
                nudHoursToBackup.Value = objPrincipalCompany.prco_hoursbetweenbackups__int;
                nudDaysToDelete.Value  = objPrincipalCompany.prco_daysdeletbackups__int;
            }
        }
        public static bool Edit(
            principalcompany objPrincipalCompany,
            string stRfc,
            string stName,
            string stAddress,
            string stPhone,
            string stEmail,
            string stFacebookUrl,
            bool boDevelopmentMode,
            int inHoursBetweenBackups,
            int inDaysDeleteBackups,
            string stNamePicture,
            byte[] byaPicture,
            string stState,
            string stCity,
            session objSession)
        {
            try
            {
                using (ModelContext objContext = new ModelContext())
                {
                    var vPreferencePrincipal = objContext.principalcompanies.Where(p => p.prco_uuid__uniqueidentifier == objPrincipalCompany.prco_uuid__uniqueidentifier).FirstOrDefault();

                    var vLastBranch = objContext.proc_principalcompany_findAllBranches(objPrincipalCompany.prco_uuid__uniqueidentifier).LastOrDefault();

                    // Add Preference
                    Guid objGuidPreferenceAux = Guid.NewGuid();
                    do
                    {
                        objGuidPreferenceAux = Guid.NewGuid();
                    } while (FindByUUID(objGuidPreferenceAux) != null);

                    principalcompany objPrincipalCompanyAux = new principalcompany()
                    {
                        prco_uuid__uniqueidentifier         = objGuidPreferenceAux,
                        prco_rfc__nvarchar                  = vPreferencePrincipal.prco_rfc__nvarchar,
                        prco_name__nvarchar                 = vPreferencePrincipal.prco_name__nvarchar,
                        prco_address__nvarchar              = vPreferencePrincipal.prco_address__nvarchar,
                        prco_phone__nvarchar                = vPreferencePrincipal.prco_phone__nvarchar,
                        prco_email__nvarchar                = vPreferencePrincipal.prco_email__nvarchar,
                        prco_facebook__nvarchar             = vPreferencePrincipal.prco_facebook__nvarchar,
                        prco_developmentmode__bit           = vPreferencePrincipal.prco_developmentmode__bit,
                        prco_hoursbetweenbackups__int       = vPreferencePrincipal.prco_hoursbetweenbackups__int,
                        prco_daysdeletbackups__int          = vPreferencePrincipal.prco_daysdeletbackups__int,
                        reso_uuid_logo__uniqueidentifier    = vPreferencePrincipal.reso_uuid_logo__uniqueidentifier,
                        city_uuid__uniqueidentifier         = vPreferencePrincipal.city_uuid__uniqueidentifier,
                        sess_uuid_used__uniqueidentifier    = null,
                        sess_uuid_created__uniqueidentifier = vPreferencePrincipal.sess_uuid_created__uniqueidentifier,
                        prco_uuid_root__uniqueidentifier    = vLastBranch.prco_uuid__uniqueidentifier
                    };
                    objContext.principalcompanies.Add(objPrincipalCompanyAux);

                    // Add City
                    Guid?objGuidCity = null;
                    if (!string.IsNullOrEmpty(stCity))
                    {
                        objGuidCity = BCity.FindByName(stCity, BState.FindByName(stState, BCountry.FindByCode("MX"))).city_uuid__uniqueidentifier;
                    }

                    // Add Resource
                    Guid?objGuidResource = null;
                    if (byaPicture != null && !string.IsNullOrEmpty(stNamePicture))
                    {
                        objGuidResource = BResource.Add(stNamePicture, 1, null, byaPicture, null).reso_uuid__uniqueidentifier;
                    }

                    vPreferencePrincipal.prco_rfc__nvarchar                  = stRfc;
                    vPreferencePrincipal.prco_name__nvarchar                 = stName;
                    vPreferencePrincipal.prco_address__nvarchar              = stAddress;
                    vPreferencePrincipal.prco_phone__nvarchar                = stPhone;
                    vPreferencePrincipal.prco_email__nvarchar                = stEmail;
                    vPreferencePrincipal.prco_facebook__nvarchar             = stFacebookUrl;
                    vPreferencePrincipal.prco_developmentmode__bit           = boDevelopmentMode;
                    vPreferencePrincipal.prco_hoursbetweenbackups__int       = inHoursBetweenBackups;
                    vPreferencePrincipal.prco_daysdeletbackups__int          = inDaysDeleteBackups;//vPreferencePrincipal.prco_timebetweenbackups__int = inTimeBetweenBackups > 0 ? inTimeBetweenBackups: null;
                    vPreferencePrincipal.reso_uuid_logo__uniqueidentifier    = objGuidResource;
                    vPreferencePrincipal.city_uuid__uniqueidentifier         = objGuidCity;
                    vPreferencePrincipal.sess_uuid_used__uniqueidentifier    = null;
                    vPreferencePrincipal.sess_uuid_created__uniqueidentifier = objSession.sess_uuid__uniqueidentifier;
                    vPreferencePrincipal.prco_uuid_root__uniqueidentifier    = null;

                    objContext.SaveChanges();

                    return(true);
                }
            }
            catch { }

            return(false);
        }