Exemple #1
0
        public static Task <bool> DeleteBackups()
        {
            return(Task.Run(() =>
            {
                if (Directory.Exists(Preferences.PathBackups))
                {
                    List <string> objList = Directory.GetFiles(Preferences.PathBackups, "*.bak").ToList();

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

                        int inDaysConfigirated = BPrincipalCompany.Get().prco_daysdeletbackups__int;

                        DateTime objDateNow = DateTime.Now;

                        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))
                            {
                                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.TotalHours > (inDaysConfigirated * 24))
                                {
                                    try
                                    {
                                        File.Delete(objList[inCont]);
                                    }
                                    catch { }
                                }
                            }
                        }

                        return true;
                    }
                }
                return false;
            }));
        }
Exemple #2
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.CheckIsNumeric(txtPhone.Text, 0, 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();
            }
        }
Exemple #3
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;
            }));
        }