예제 #1
0
        public static Task <int> DoBackup()
        {
            return(Task.Run(() =>
            {
                try
                {
                    if (Directory.Exists(Preferences.PathBackups))
                    {
                        Directory.CreateDirectory(Preferences.PathBackups);
                    }

                    List <string> objList = Directory.GetFiles(Preferences.PathBackups, "*.bak").ToList();

                    if (objList != null)
                    {
                        objList.OrderBy(l => l);

                        for (int inCont = 0; inCont < objList.Count; inCont++)
                        {
                            if (objList[inCont].Split('\\').Length != 4 || objList[inCont].Split('\\')[3].Length != 63 || !objList[inCont].Contains(Preferences.DatabaseName) && !RegularExpressions.CheckIsNumeric(objList[inCont].Split('\\')[3].Substring(47, 12), 12, 12))//if (objList[inCont].Split('\\').Length != 4 || objList[inCont].Split('\\')[3].Length != 63 || !objList[inCont].Contains(Preferences.DatabaseName) && !RegularExpressions.CheckIsNumeric(objList.Last().Split('\\')[3].Substring(47, 12), 12, 12))
                            {
                                objList.RemoveAt(inCont);
                            }
                        }
                    }

                    DateTime objDateNow = DateTime.Now;

                    string stQuery = "USE master; BACKUP DATABASE " + Preferences.DatabaseName + " TO DISK = N'" + Preferences.PathBackups + "\\" + Preferences.DatabaseName + "_auto_" + DateTime.Now.Year.ToString().Substring(2, 2) + (objDateNow.Month < 10 ? "0" + objDateNow.Month : objDateNow.Month.ToString()) + (objDateNow.Day < 10 ? "0" + objDateNow.Day : objDateNow.Day.ToString()) + "" + (objDateNow.Hour < 10 ? "0" + objDateNow.Hour : objDateNow.Hour.ToString()) + "" + (objDateNow.Minute < 10 ? "0" + objDateNow.Minute : objDateNow.Minute.ToString()) + "" + (objDateNow.Second < 10 ? "0" + objDateNow.Second : objDateNow.Second.ToString()) + ".bak' WITH NOFORMAT, NOINIT, NAME = N'test-Completa Base de datos Copia de seguridad', SKIP, NOREWIND, NOUNLOAD, STATS = 10;";

                    if (objList == null || objList.Count == 0)
                    {
                        if (Business.Execute(stQuery))
                        {
                            return BPrincipalCompany.Get().prco_hoursbetweenbackups__int;
                        }
                    }
                    else
                    {
                        int inHoursConfigirated = BPrincipalCompany.Get().prco_hoursbetweenbackups__int;

                        string stDateTime = objList.Last().Split('\\')[3].Substring(47, 12);

                        int inYear = Convert.ToInt32("20" + stDateTime.Substring(0, 2));
                        int inMonth = Convert.ToInt32(stDateTime.Substring(2, 2));
                        int inDay = Convert.ToInt32(stDateTime.Substring(4, 2));
                        int inHour = Convert.ToInt32(stDateTime.Substring(6, 2));
                        int inMinute = Convert.ToInt32(stDateTime.Substring(8, 2));
                        int inSecond = Convert.ToInt32(stDateTime.Substring(10, 2));

                        TimeSpan objTimeSpan = objDateNow - new DateTime(inYear, inMonth, inDay, inHour, inMinute, inSecond);

                        if (objTimeSpan.TotalMinutes > (inHoursConfigirated * 60))
                        {
                            if (Business.Execute(stQuery))
                            {
                                return inHoursConfigirated;
                            }
                        }
                        else
                        {
                            return Convert.ToInt32((inHoursConfigirated * 60) - objTimeSpan.TotalMinutes);
                        }
                    }
                }

                catch { }

                return 0;
            }));
        }
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtRFC.Text) || RegularExpressions.CheckIsRFC(txtRFC.Text))
            {
                if (RegularExpressions.CheckIsNormalText(txtCompany.Text, 1, 100))
                {
                    if (RegularExpressions.CheckIsNormalText(txtAddress.Text, 0, 255))
                    {
                        if (RegularExpressions.CheckIsNumber(txtPhone.Text, 10, 10))
                        {
                            if (string.IsNullOrEmpty(txtEmail.Text) || RegularExpressions.CheckIskEmail(txtEmail.Text))
                            {
                                if (RegularExpressions.CheckIsUrl(txtFacebook.Text))
                                {
                                    if (cboState.SelectedIndex < 1 || cboCity.SelectedIndex > -1)
                                    {
                                        byte[] logo = null;
                                        if (pcbLogo.Image != null)
                                        {
                                            logo = Tools.ConvertirImagenAByte(pcbLogo.Image);
                                        }

                                        if (BPrincipalCompany.Edit(
                                                objPrincipalCompany,
                                                !string.IsNullOrEmpty(txtRFC.Text) ? txtRFC.Text : null,
                                                txtCompany.Text,
                                                !string.IsNullOrEmpty(txtAddress.Text) ? txtAddress.Text : null,
                                                !string.IsNullOrEmpty(txtPhone.Text) ? txtPhone.Text : null,
                                                !string.IsNullOrEmpty(txtEmail.Text) ? txtEmail.Text : null,
                                                !string.IsNullOrEmpty(txtFacebook.Text) ? txtFacebook.Text : null,
                                                cboMode.SelectedIndex == 0 ? true : false,
                                                Convert.ToInt32(nudHoursToBackup.Value),
                                                Convert.ToInt32(nudDaysToDelete.Value),
                                                stPathPicture,
                                                logo,
                                                cboState.SelectedIndex > 0 ? cboState.Text : null,
                                                cboCity.SelectedIndex > -1 ? cboCity.Text : null,
                                                ObjForm_004.ObjSession
                                                ))
                                        {
                                            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;
                                            nudDaysToDelete.Enabled  = false;
                                            pcbLogo.Enabled          = false;

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

                                            btnClose.Enabled = true;

                                            byAction = 0;

                                            MessageBox.Show(Preferences.GlobalSuccessOperation, Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        }
                                        else
                                        {
                                            MessageBox.Show(Preferences.GlobalErrorOperation, Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("The city must be selected if you selected some city.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        cboCity.Focus();
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("The facebook isn't correct.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    txtFacebook.Focus();
                                }
                            }
                            else
                            {
                                MessageBox.Show("The email isn't correct.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                txtEmail.Focus();
                            }
                        }
                        else
                        {
                            MessageBox.Show("The phone isn't correct.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            txtPhone.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("The address isn't correct.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtAddress.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("The company isn't correct.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtCompany.Focus();
                }
            }
            else
            {
                MessageBox.Show("The RFC isn't correct.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtRFC.Focus();
            }
        }
        private bool RefreshMainValues()
        {
            if (cboType.SelectedIndex > -1)
            {
                try
                {
                    var vPrincipalCompany = BPrincipalCompany.Get();

                    if (cboType.SelectedIndex == 0)
                    {
                        var vUsers = BUser.GetAllUsers();

                        List <Report_Users_001> objListReport = new List <Report_Users_001>();

                        if (vUsers != null)
                        {
                            for (int inCont = 0; inCont < vUsers.Count; inCont++)
                            {
                                string stCreatedBy, stModifiedBy;
                                stCreatedBy = stModifiedBy = "";

                                var vUserBranches = BUser.GetAllBranches(vUsers[inCont].user_uuid__uniqueidentifier);

                                if (vUserBranches != null && vUserBranches.Count > 1)
                                {
                                    var vUser = BUser.FindByUUID(vUserBranches[0].user_uuid__uniqueidentifier.Value);

                                    stCreatedBy = Tools.Decrypt(vUser.user_firstname__nvarchar) + " " + Tools.Decrypt(vUser.user_lastname__nvarchar);

                                    vUser = BUser.FindByUUID(vUserBranches[vUserBranches.Count - 1].user_uuid__uniqueidentifier.Value);

                                    stModifiedBy = Tools.Decrypt(vUser.user_firstname__nvarchar) + " " + Tools.Decrypt(vUser.user_lastname__nvarchar);
                                }
                                else
                                {
                                    stCreatedBy = Tools.Decrypt(vUsers[inCont].user_firstname__nvarchar) + " " + Tools.Decrypt(vUsers[inCont].user_lastname__nvarchar);
                                }

                                objListReport.Add(new Report_Users_001()
                                {
                                    Number             = Convert.ToString(inCont + 1),
                                    Username           = vUsers[inCont].user_username__nvarchar,
                                    Email              = vUsers[inCont].user_email__nvarchar,
                                    Cellphone          = vUsers[inCont].user_cellphone__nvarchar,
                                    FirstName          = Tools.Decrypt(vUsers[inCont].user_firstname__nvarchar),
                                    LastName           = Tools.Decrypt(vUsers[inCont].user_lastname__nvarchar),
                                    RoleAccess         = vUsers[inCont].user_roleaccess__tinyint == 1 ? "Administrator" : "<>",
                                    CreatedBy          = stCreatedBy,
                                    LastModificationBy = stModifiedBy
                                });
                            }
                        }
                        ///////////////////////////////////////////////////////////////////////////////

                        rpvReport.LocalReport.ReportEmbeddedResource = "General_Desktop_Application.Reports.Report_Users_001.rdlc";

                        // We clean DataSource of report.
                        rpvReport.LocalReport.DataSources.Clear();

                        //
                        // We establish the parameters that we'll send them to report.
                        //
                        string            stPUser            = Tools.Decrypt(ObjForm_004.ObjUser.user_firstname__nvarchar) + " " + Tools.Decrypt(ObjForm_004.ObjUser.user_lastname__nvarchar);
                        string            stPCompany         = vPrincipalCompany.prco_name__nvarchar;
                        string            stPAddress         = vPrincipalCompany.prco_address__nvarchar != null ? vPrincipalCompany.prco_address__nvarchar : "";
                        ReportParameter[] objReportParameter =
                        {
                            new ReportParameter("pReportName", "User Report"),
                            new ReportParameter("pLogo",       vPrincipalCompany.reso_uuid_logo__uniqueidentifier != null ? Convert.ToBase64String(BResource.FindByUUID(vPrincipalCompany.reso_uuid_logo__uniqueidentifier.Value).reso_value__varbinary) : null),
                            new ReportParameter("pDate",       DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString()),
                            new ReportParameter("pCompany",    stPCompany.Length > 20 ? stPCompany.Substring(0,                                                                                                                                                20) : stPCompany),
                            new ReportParameter("pRFC",        vPrincipalCompany.prco_rfc__nvarchar != null ? vPrincipalCompany.prco_rfc__nvarchar :null),
                            new ReportParameter("pUser",       stPUser.Length > 20 ? stPUser.Substring(0,                                                                                                                                                         20) : stPUser),
                            new ReportParameter("pAddress",    stPAddress.Length > 20 ? stPAddress.Substring(0, 20):stPAddress)
                        };

                        // We send the list with parameters.
                        rpvReport.LocalReport.SetParameters(objReportParameter);

                        //
                        // We establish the list as report's Datasource.
                        //
                        rpvReport.LocalReport.DataSources.Add(new ReportDataSource("dsReport_User_001", objListReport));

                        // We adjust the report's visualization mode.

                        rpvReport.SetDisplayMode(DisplayMode.PrintLayout);

                        rpvReport.ZoomMode    = ZoomMode.Percent;
                        rpvReport.ZoomPercent = 100;

                        //
                        // We do a refresh to reportViewer.
                        //
                        rpvReport.RefreshReport();
                    }
                }
                catch
                {
                    MessageBox.Show(Preferences.GlobalErrorOperation, Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Information);

                    return(false);
                }
            }

            return(true);
        }