Пример #1
0
        private BitInfo GetBitInfo(string bitPath)
        {
            BitInfo bitinfo = null;

            SqliteHelper.SqliteHelper mysql = new SqliteHelper.SqliteHelper();
            if (!mysql.DBConnect(_localDBname))
            {
                throw new Exception("连接数据库失败");
            }

            string    sql   = "select * from u_picture where u_picture.picture_file='" + bitPath + "';";
            DataTable bitDt = mysql.DBReadTable(sql);

            mysql.DBDisConnect();

            if (bitDt == null)
            {
                throw new Exception("查询数据库失败");
            }
            else if (bitDt.Rows.Count == 0)
            {
                bitinfo = new BitInfo();
                GetBitmapInfo(bitPath, bitinfo);
            }
            else if (bitDt.Rows.Count == 1)
            {
                BitInfo[] bitinfos = DataTableConvert.TableToT <BitInfo>(bitDt);
                bitinfo = bitinfos[0];
            }
            else
            {
                throw new Exception("数据库数据有误,存在多条相同的记录");
            }
            return(bitinfo);
        }
Пример #2
0
        /// <summary>
        /// 下载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDownload_MouseUp(object sender, MouseEventArgs e)
        {
            if (_pathArray == null)
            {
                return;
            }
            FolderBrowserDialog gbd = new FolderBrowserDialog();

            if (gbd.ShowDialog() == DialogResult.OK)
            {
                string path = gbd.SelectedPath + "\\记录表_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                SqliteHelper.SqliteHelper mysql = new SqliteHelper.SqliteHelper();
                if (!mysql.DBConnect(_localDBname))
                {
                    MessageBox.Show("查询数据库失败");
                }
                try
                {
                    string    content = string.Join("','", _pathArray);
                    string    sql     = "select picture_name as 文件名称, picture_file as 路径, picture_title as 标题,picture_time as 时间,picture_author as 作者,picture_level as 评级,picture_info as 摘要,picture_key as 关键词,picture_person as 人物,picture_org as 机构,picture_type as 分类,picture_marker as 标引人,picture_marktime as 标引时间,picture_width as 图片宽,picture_height as 图片高,picture_hr as 水平分辨率,picture_vr as 垂直分辨率,picture_bit as 位深度,picture_gps as gps信息,picture_size as 图片大小,picture_format as 图片格式 from u_picture where picture_file in ('" + content + "')";
                    DataTable dt      = mysql.DBReadTable(sql);
                    if (dt == null)
                    {
                        throw new Exception("查询数据库失败");
                    }
                    bool res = ExcelHandler.Write(path, dt);
                    if (!res)
                    {
                        throw new Exception("导出表格失败");
                    }
                    else
                    {
                        MessageBox.Show("导出成功");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    mysql.DBDisConnect();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpload_MouseUp(object sender, MouseEventArgs e)
        {
            //未选中图片时点击上传
            if (_pathArray == null)
            {
                return;
            }
            SqliteHelper.SqliteHelper mysql = new SqliteHelper.SqliteHelper();
            try
            {
                btnUpload.Enabled = false;

                if (_pathArray.Length == 1)
                {
                    BitInfo bitinfo = this.pg_context.SelectedObject as BitInfo;
                    if (!mysql.DBConnect(_localDBname))
                    {
                        throw new Exception("连接数据库失败");
                    }
                    string res = InsertDB(_pathArray[0], bitinfo, mysql);
                }
                else if (_pathArray.Length > 1)
                {
                    BitInfo   bitinfo      = this.pg_context.SelectedObject as BitInfo;
                    BitInfo[] bitInfoArray = new BitInfo[_pathArray.Length];
                    for (int i = 0; i < _pathArray.Length; i++)
                    {
                        bitInfoArray[i] = bitinfo.Clone();
                        GetBitmapInfo(_pathArray[i], bitInfoArray[i]);
                    }

                    if (!mysql.DBConnect(_localDBname))
                    {
                        throw new Exception("连接数据库失败");
                    }
                    string res = string.Empty;
                    for (int i = 0; i < _pathArray.Length; i++)
                    {
                        res = InsertDB(_pathArray[0], bitInfoArray[i], mysql);
                        if (!string.IsNullOrEmpty(res))
                        {
                            throw new Exception(res);
                        }
                    }
                }
                else
                {
                    throw new Exception("数据库数据有误,存在多条相同的记录");
                }
                MessageBox.Show("上传成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                btnUpload.Enabled = true;
                mysql.DBDisConnect();
            }
        }