Exemple #1
0
        ///Загрузить картинку в БД.
        private bool ImageAdd(string FileNameFull)
        {
            string     FileData    = "";
            string     ErrorMes    = "";
            string     ImageWidth  = "";
            string     ImageHeight = "";
            const bool ShowMes     = true;

            if (!FBAFile.FileReadToBase64(FileNameFull, out FileData, out ErrorMes, ShowMes))
            {
                return(false);
            }
            string ImageName     = Path.GetFileNameWithoutExtension(FileNameFull);
            string ImageFileName = Path.GetFileName(FileNameFull);
            string Format        = Path.GetExtension(ImageFileName).ToUpper();

            try
            {
                var pictureBoxTemp = new FBA.PictureBoxFBA();
                pictureBoxTemp.PictureBoxLoadFile(FileNameFull);
                ImageWidth  = pictureBoxTemp.Image.Width.ToString();
                ImageHeight = pictureBoxTemp.Image.Height.ToString();
            } catch (Exception ex)
            {
                sys.SM("Ошибка при открытии изображения: " + FileNameFull + Var.CR + ex.Message);
                return(false);
            }

            string sql = "INSERT INTO fbaImage (" +
                         "UserCreateID, DateCreate, Name, " +
                         "FileName, FileNameFull, Image, " +
                         "Width, Height, Format) " +
                         "VALUES (" + Var.UserID + ", " + sys.DateTimeCurrent() + ",'" + ImageName + "'," +
                         "'" + ImageFileName + "','" + FileNameFull + "','" + FileData + "'," +
                         "'" + ImageWidth + "','" + ImageHeight + "','" + Format + "')";

            if (!sys.Exec(DirectionQuery.Remote, sql))
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Загрузить шаблон отчета в БД.
        /// </summary>
        /// <returns></returns>
        private bool ReportInsert()
        {
            string     fileData           = "";
            string     errorMes           = "";
            string     reportFileNameFull = tbFileName.Text;
            const bool showMes            = true;

            if (reportFileNameFull != "")
            {
                if (!FBAFile.FileReadToBase64(reportFileNameFull, out fileData, out errorMes, showMes))
                {
                    return(false);
                }
            }
            string reportName     = tbName.Text;
            string reportBrief    = tbBrief.Text;
            string reportFileName = Path.GetFileName(reportFileNameFull);
            string format         = tbFormat.Text;
            string comment        = tbComment.Text;
            string reportType     = GetReportType(format);

            string SQL = "INSERT INTO fbaReport (" +
                         "EntityID, DateCreate, UserCreateID, " +
                         "Format, Brief, Name, " +
                         "FileName, FileNameFull, FileData, " +
                         "Comment, ReportType)" +
                         "VALUES (" +
                         "113," + sys.DateTimeCurrent() + "," + Var.UserID + "," +
                         "'" + format + "','" + reportBrief + "','" + reportName + "'," +
                         "'," + reportFileName + "','" + reportFileNameFull + "','" + fileData + "'," +
                         "'," + comment + "','" + reportType + "')";

            if (!sys.Exec(DirectionQuery.Remote, SQL))
            {
                return(false);
            }
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Загрузить шаблон отчета в БД.
        /// </summary>
        /// <returns>Если успешно, то true</returns>
        private bool ReportUpdate()
        {
            string     fileData           = "";
            string     errorMes           = "";
            string     reportFileNameFull = tbFileName.Text;
            const bool showMes            = true;

            if (!FBAFile.FileReadToBase64(reportFileNameFull, out fileData, out errorMes, showMes))
            {
                return(false);
            }
            string reportName     = tbName.Text;
            string reportBrief    = tbBrief.Text;
            string reportFileName = Path.GetFileName(reportFileNameFull);
            string format         = tbFormat.Text;
            string comment        = tbComment.Text;
            string reportType     = GetReportType(format);
            string sql            = "UPDATE fbaReport " +
                                    "SET " +
                                    "DateChange    = " + sys.DateTimeCurrent() +
                                    ",UserChangeID = " + Var.UserID +
                                    ",Format       = '" + format + "'" +
                                    ",Brief        = '" + reportBrief + "'" +
                                    ",Name         = '" + reportName + "'" +
                                    ",FileName     = '" + reportFileName + "'" +
                                    ",FileNameFull = '" + reportFileNameFull + "'" +
                                    ",FileData     = '" + fileData + "'" +
                                    ",Comment      = '" + comment + "'" +
                                    ",ReportType   = '" + reportType + "'" +
                                    " WHERE ID = " + ID;

            if (!sys.Exec(DirectionQuery.Remote, sql))
            {
                return(false);
            }
            return(true);
        }
Exemple #4
0
        //Показывает список доступных обновлений.



        //Сохранить все файлы программы на сервере.
        //   //UserUpdate  - обновление доступно пользователям.
        //Upload      - Загрузить файлы на сервер.
        //ContentList - Cписок файлов и папок для обновления в определенном формате:
        //              ADDDIR:  CustomDorectoryName
        //              DELDIR:  CustomDorectoryName
        //              ADDFILE: CustomFileName.txt
        //              DELFILE: CustomFileName.txt



        /// <summary>
        ///
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="contentList"></param>
        /// <param name="doUserUpdate"></param>
        /// <param name="uploadToServer"></param>
        /// <returns></returns>
        private bool UpdateUploadFiles(out System.Data.DataTable dt, string[] contentList, bool doUserUpdate, bool uploadToServer)
        {
            dt = new System.Data.DataTable();
            string sql = "";

            //Для вставки полей в DT.
            string numberFile;
            int    numberUpdate;
            string dateRecord  = sys.DateTimeToSQLStr(DateTime.Now);
            string userUpdate  = (!doUserUpdate).ToInt().ToString();
            string contentType = "";
            string operation   = "";
            string version     = Var.ApplicationVersion;
            string fullName    = "";
            string path        = FBAPath.PathMain;
            string fileName    = "";
            string extension   = "";
            string creationTime;
            string lastWriteTime;
            string lastAccessTime;
            long   SizeFile;
            string hashMD5;
            string fileData = ""; //Данные в Base64.



            //Последняя версия в таблице обновлений.
            sql = "SELECT MAX(NumberUpdate) AS NumberVersion FROM fbaUpdate; ";
            string NumberUpdateStr = sys.GetValue(DirectionQuery.Remote, sql);

            if (NumberUpdateStr == "")
            {
                NumberUpdateStr = "0";
            }
            numberUpdate = NumberUpdateStr.ToInt() + 1; //Новая варсия.
            bool ff = true;
            Type tp = ff.GetType();

            dt.Columns.Add("Check", tp);      //Выбрать файл для заливки
            dt.Columns.Add("NumberFile");     //Порядковый номер файла или папки в обновлении
            dt.Columns.Add("NumberUpdate");   //Порядковый номер обновления.
            dt.Columns.Add("DateRecord");     //Текущая дата.
            dt.Columns.Add("UserUpdate");     //true-Пользователям нужно обновляться из это обновления. false-не нужно. false-нужно для тестирования, для отложенного обновления и др.
            dt.Columns.Add("ContentType");    //1-папка, 2-файл
            dt.Columns.Add("Operation");      //1-создать, 2-удалить.
            dt.Columns.Add("Version");        //Версия программы вида 1.0.6335.33362
            dt.Columns.Add("FullName");       //Полное имя файла с путем.
            dt.Columns.Add("Path");           //Начальный каталог программы, т.е. sys.PathMain
            dt.Columns.Add("Name");           //Имя файла/папки
            dt.Columns.Add("Extension");      //Расширение файла (для папки здесь пусто)
            dt.Columns.Add("CreationTime");   //Дата создания папки/файла
            dt.Columns.Add("LastWriteTime");
            dt.Columns.Add("LastAccessTime");
            dt.Columns.Add("Size");           //размер файла в байтах. Для папки здесь 0.
            dt.Columns.Add("MD5");            //Хеш MD5
                                              //DT.Columns.Add("FileData");    //Содержимое файла в кодировке Base64.


            sql = "DELETE FROM fbaUpdate WHERE Version = '" + version + "'; ";
            if (!sys.Exec(DirectionQuery.Remote, sql))
            {
                return(false);
            }


            var fileprop  = new string[16];
            var progress1 = new FormProgress("Обновление", "Получение свойств файлов", contentList.Length);

            progress1.Show();
            for (int i = 0; i < contentList.Length; i++)
            {
                fullName   = contentList[i];
                numberFile = (i + 1).ToString();

                if (!File.Exists(fileName))
                {
                    continue;
                }
                var file = new FileInfo(fullName);
                fileName       = file.Name;
                extension      = file.Extension;
                creationTime   = sys.DateTimeToSQLStr(file.CreationTime);
                lastWriteTime  = sys.DateTimeToSQLStr(file.LastWriteTime);
                lastAccessTime = sys.DateTimeToSQLStr(file.LastAccessTime);
                SizeFile       = file.Length;
                hashMD5        = Crypto.FileHashMD5Calc(fullName);

                fileprop[0]  = numberFile;
                fileprop[1]  = numberUpdate.ToString();
                fileprop[2]  = dateRecord;
                fileprop[3]  = userUpdate;
                fileprop[4]  = ""; //ContentType.ToString();
                fileprop[5]  = ""; //Operation.ToString();
                fileprop[6]  = version;
                fileprop[7]  = fullName;
                fileprop[8]  = path;
                fileprop[9]  = fileName;
                fileprop[10] = extension;
                fileprop[11] = creationTime;
                fileprop[12] = lastWriteTime;
                fileprop[13] = lastAccessTime;
                fileprop[14] = SizeFile.ToString();
                fileprop[15] = hashMD5;

                DataRow row = dt.NewRow();
                row.ItemArray = fileprop;
                dt.Rows.Add(row);
                if (uploadToServer)
                {
                    fileData = "";
                    string     errorMes;
                    const bool showMes = true;
                    if (!FBAFile.FileReadToBase64(fullName, out fileData, out errorMes, showMes))
                    {
                        return(false);
                    }

                    const bool saveHashToEndFile = false;
                    if (!FBAFile.FileGetBase64WithHashMD5(fileName, saveHashToEndFile, out fileData, out hashMD5))
                    {
                        return(false);
                    }

                    sql = @"INSERT INTO fbaUpdate (NumberFile, NumberUpdate, DateRecord, UserUpdate, " +
                          "ContentType, Operation, Version, CurrentVersion, FullName, Path, Name, Extension, " +
                          "CreationTime, LastWriteTime, LastAccessTime, Size, MD5, " +
                          "FileData) " +
                          "VALUES (" +
                          "'" + numberFile + "','" + numberUpdate + "','" + dateRecord + "','" + userUpdate + "'," +
                          "'" + contentType + "','" + operation + "','" + version + "','" + version + "','" + fullName + "','" + path + "','" + fileName + "','" + extension + "'," +
                          "'" + creationTime + "','" + lastWriteTime + "','" + lastAccessTime + "'," + SizeFile.ToString() + ", '" + hashMD5 + "'," +
                          "'" + fileData + "'); " + Var.CR;
                    if (!sys.Exec(DirectionQuery.Remote, sql))
                    {
                        return(false);
                    }
                }
                progress1.Inc();
            }

            //В конце загрузки файлов на сервер обновляем информцию о текущей версии.
            if (uploadToServer)
            {
                sql = @"UPDATE fbaUpdate SET CurrentVersion = '" + version + "'; " + Var.CR;
                if (!sys.Exec(DirectionQuery.Remote, sql))
                {
                    return(false);
                }
            }
            progress1.Dispose();
            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Загрузка обновления на сервер.
        /// </summary>
        /// <returns></returns>
        private bool UploadNewUpdate()
        {
            string version = dt.Value("Version");

            if (!DeleteUpdate(version))
            {
                return(false);
            }
            string fileName  = "";
            string sql       = "";
            var    progress1 = new FormProgress("Обновление", "Загрузка файлов обновления на сервер", dt.Rows.Count);

            progress1.Show();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                try
                {
                    string fullName = dt.Value(i, "FullName");
                    if (!File.Exists(fullName))
                    {
                        continue;
                    }
                    string     fileData;
                    string     errorMes;
                    const bool showMes = true;
                    bool       check   = dt.Value(i, 0).ToBool();
                    if (!check)
                    {
                        continue;
                    }
                    string       numberFile   = progress1.Progress.ToString();
                    string       numberUpdate = dt.Value(i, "NumberUpdate");
                    string       dateRecord   = sys.GetDateTimeNow();
                    string       userUpdate   = Var.UserID.ToString();
                    const string contentType  = "";
                    const string operation    = "";
                    string       path         = dt.Value(i, "Path");
                    fileName = dt.Value(i, "Name");
                    string extension      = dt.Value(i, "Extension");
                    string creationTime   = dt.Value(i, "CreationTime");
                    string lastWriteTime  = dt.Value(i, "LastWriteTime");
                    string lastAccessTime = dt.Value(i, "LastAccessTime");
                    string sizeFile       = dt.Value(i, "Size");
                    string hashMD5        = dt.Value(i, "MD5");
                    if (!FBAFile.FileReadToBase64(fullName, out fileData, out errorMes, showMes))
                    {
                        return(false);
                    }

                    sql = @"INSERT INTO fbaUpdate (NumberFile, NumberUpdate, DateRecord, UserUpdate, " +
                          "ContentType, Operation, Version, CurrentVersion, FullName, Path, Name, Extension, " +
                          "CreationTime, LastWriteTime, LastAccessTime, Size, MD5, " +
                          "FileData) " +
                          "VALUES (" +
                          "'" + numberFile + "','" + numberUpdate + "','" + dateRecord + "','" + userUpdate + "'," +
                          "'" + contentType + "','" + operation + "','" + version + "','" + version + "','" + fullName + "','" + path + "','" + fileName + "','" + extension + "'," +
                          "'" + creationTime + "','" + lastWriteTime + "','" + lastAccessTime + "'," + sizeFile.ToString() + ", '" + hashMD5 + "'," +
                          "'" + fileData + "'); " + Var.CR;
                    if (!sys.Exec(DirectionQuery.Remote, sql))
                    {
                        return(false);
                    }
                } catch (Exception ex)
                {
                    sys.SM("Ошибка загрузки файла обновления: " + Var.CR + fileName + Var.CR + ex.Message);
                }
                progress1.Inc();
            }

            //В конце загрузки файлов на сервер обновляем информцию о текущей версии.
            sql = @"UPDATE fbaUpdate SET CurrentVersion = '" + version + "'; " + Var.CR;
            if (!sys.Exec(DirectionQuery.Remote, sql))
            {
                return(false);
            }

            progress1.Dispose();
            return(true);
        }