244 lines
8.4 KiB
C#
244 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Reflection;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Diagnostics;
|
|
using CommonLib;
|
|
using DevExpress.XtraEditors;
|
|
|
|
namespace Lskj.CmCapture
|
|
{
|
|
public partial class FrmCmCapture : Form
|
|
{
|
|
private Dictionary<String, FileModel> data = new Dictionary<string, FileModel>();
|
|
private String fileDir = "\\temp_cm_capture\\";
|
|
private int typeid = 0;
|
|
public string DirId { get; set; }
|
|
public string OperatorId { get; set; }
|
|
public string speciesno { get; set; }
|
|
private DataTable dt;
|
|
|
|
public FrmCmCapture()
|
|
{
|
|
InitializeComponent();
|
|
gridView1.DoubleClick += new EventHandler(gridView1_DoubleClick);
|
|
}
|
|
|
|
void gridView1_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
int[] rows = gridView1.GetSelectedRows();
|
|
if (rows.Length > 0)
|
|
{
|
|
DataRow row = gridView1.GetDataRow(rows[0]);
|
|
Process.Start(PubUtil.AbsolutelyPath + fileDir + row["Name"]);
|
|
}
|
|
}
|
|
|
|
private void FrmCmCapture_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
axCmCaptureOcx1.Initial();
|
|
//axCmCaptureOcx1.AutoCrop(1);
|
|
axCmCaptureOcx1.StartRun(typeid); //0摄像头,1拍摄仪,2辅助拍摄
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
String guid = Guid.NewGuid().ToString();
|
|
axCmCaptureOcx1.CaptureImage(PubUtil.AbsolutelyPath + fileDir + guid + ".bmp");
|
|
|
|
data.Add(guid, new FileModel(data.Keys.Count + 1, guid + ".bmp", DateTime.Now, guid));
|
|
List<FileModel> list = new List<FileModel>();
|
|
foreach (String s in data.Keys)
|
|
{
|
|
list.Add(data[s]);
|
|
}
|
|
gcMain.DataSource = ToDataTableTow(list);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnUpload_Click(object sender, EventArgs e)
|
|
{
|
|
dt = gcMain.DataSource as DataTable;
|
|
if ((dt == null) || (dt.Rows.Count < 1))
|
|
{
|
|
MessageBox.Show("没有需要上传的文件");
|
|
return;
|
|
}
|
|
btnAdd.Enabled = false;
|
|
btnUpload.Enabled = false;
|
|
btnDelete.Enabled = false;
|
|
label1.Text = "上传中...";
|
|
|
|
if (dt != null)
|
|
{
|
|
progressBar1.Maximum = dt.Rows.Count;
|
|
new Thread(Uploader).Start();
|
|
}
|
|
}
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
{
|
|
base.OnClosing(e);
|
|
axCmCaptureOcx1.Dispose();
|
|
}
|
|
|
|
public void Uploader()
|
|
{
|
|
try
|
|
{
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
DataRow row = dt.Rows[i];
|
|
String path = PubUtil.AbsolutelyPath + fileDir + row["Name"].ToString().Trim();
|
|
if (!File.Exists(path))
|
|
{
|
|
MessageBox.Show("file not exists");
|
|
|
|
btnAdd.Enabled = true;
|
|
btnUpload.Enabled = true;
|
|
btnDelete.Enabled = true;
|
|
return;
|
|
}
|
|
//Image image = Image.FromFile(path);
|
|
//System.IO.MemoryStream Ms = new MemoryStream();
|
|
//image.Save(Ms, System.Drawing.Imaging.ImageFormat.Bmp);
|
|
//MessageBox.Show(Ms.Length + " " + speciesno);
|
|
|
|
FileStream info = File.OpenRead(path);
|
|
byte[] img = new byte[info.Length];
|
|
info.Read(img, 0, Convert.ToInt32(info.Length));
|
|
info.Close();
|
|
|
|
|
|
//Ms.Position = 0;
|
|
//Ms.Read(img, 0, Convert.ToInt32(Ms.Length));
|
|
//Ms.Close();
|
|
|
|
progressBar1.Value = i;
|
|
net.eicp.fsdfh9.Uploader uploader = new net.eicp.fsdfh9.Uploader();
|
|
net.eicp.fsdfh9.ResultFile rf = uploader.UploadFile(img, DirId, row["Name"].ToString().Trim());
|
|
if (rf.Status == 0)
|
|
{
|
|
var name = row["name"] + "";
|
|
var size = Convert.ToInt64(img.Length);
|
|
string sqlValue = string.Format("INSERT INTO P_fm_FileTab(sName,ParentID,fileSize,creator,speciesno,CreateTime) " +
|
|
"VALUES('{0}',{1},'{2}',{3},'{4}','{5}')", row["Name"].ToString().Trim(), DirId, size, OperatorId, speciesno, DateTime.Now);
|
|
SqlHelper.ExecuteNonQuery(sqlValue);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("图片上传失败" + rf.ErrorMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
progressBar1.Value = dt.Rows.Count;
|
|
btnAdd.Enabled = true;
|
|
btnUpload.Enabled = true;
|
|
btnDelete.Enabled = true;
|
|
label1.Text = "完成";
|
|
MessageBox.Show("图片上传成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void radioButton3_Click(object sender, EventArgs e)
|
|
{
|
|
RadioButton rb = (RadioButton)sender;
|
|
typeid = Convert.ToInt32(rb.Tag);
|
|
|
|
//axCmCaptureOcx1.Destory();
|
|
|
|
//axCmCaptureOcx1.Initial();
|
|
//axCmCaptureOcx1.AutoCrop(1);
|
|
int result = axCmCaptureOcx1.StartRun(typeid); //0摄像头,1拍摄仪,2辅助拍摄
|
|
}
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
int[] rows = gridView1.GetSelectedRows();
|
|
for (int i = 0; i < rows.Length; i++)
|
|
{
|
|
DataRow row = gridView1.GetDataRow(rows[i]);
|
|
String guid = row["key"].ToString();
|
|
data.Remove(guid);
|
|
if (File.Exists(fileDir + guid + ".bmp"))
|
|
{
|
|
File.Delete(fileDir + guid + ".bmp");
|
|
}
|
|
}
|
|
List<FileModel> list = new List<FileModel>();
|
|
foreach (String s in data.Keys)
|
|
{
|
|
list.Add(data[s]);
|
|
}
|
|
gcMain.DataSource = ToDataTableTow(list);
|
|
}
|
|
|
|
// <summary>
|
|
/// 将集合类转换成DataTable
|
|
/// </summary>
|
|
/// <param name="list">集合</param>
|
|
/// <returns></returns>
|
|
public DataTable ToDataTableTow(IList list)
|
|
{
|
|
DataTable result = new DataTable();
|
|
if (list.Count > 0)
|
|
{
|
|
PropertyInfo[] propertys = list[0].GetType().GetProperties();
|
|
foreach (PropertyInfo pi in propertys)
|
|
{
|
|
result.Columns.Add(pi.Name, pi.PropertyType);
|
|
}
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
ArrayList tempList = new ArrayList();
|
|
foreach (PropertyInfo pi in propertys)
|
|
{
|
|
object obj = pi.GetValue(list[i], null);
|
|
tempList.Add(obj);
|
|
}
|
|
object[] array = tempList.ToArray();
|
|
result.LoadDataRow(array, true);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class FileModel
|
|
{
|
|
public FileModel(int Id, String Name, DateTime Created, String key)
|
|
{
|
|
this.Id = Id;
|
|
this.Name = Name;
|
|
this.Created = Created;
|
|
this.key = key;
|
|
}
|
|
public int Id { get; set; }
|
|
public string Name { get; set; }
|
|
public DateTime Created { get; set; }
|
|
public string key { get; set; }
|
|
}
|
|
}
|