private int _count=0;
private int m_count = 0;
System.IO.FileInfo[] fi = null;
System.IO.DirectoryInfo di = null;
private List<string> list;
/// <summary>
/// 上传图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void btn_upfile_Click(object sender, System.EventArgs e)
{
_count = 0; m_count = 0; fi = null; di = null; list = new List<string>();
if (FT)
UtilityClass.SetMessage("请先确定放行后,再图挡拍照及上传", this);
if (Environment.ExternalStorageState != Environment.MediaMounted)
UtilityClass.SetMessage("请插入SD卡", this);
Java.IO.File _upfile=UtilityClass.retDirectoryForPictures(ID);
if (_upfile == null || _upfile.ToString().Trim().Length == 0)
{
UtilityClass.SetMessage("请进行拍图再上传!", this);
return; }
di = new System.IO.DirectoryInfo(_upfile.ToString().Trim());
fi = di.GetFiles("*"+@"_"+ID.ToString().Trim()+@".jpeg");
//和数据库中的图片对比,只上传没有保存的图片,其它则删除
System.Data.DataTable dt=swe.GetJpeg(ID, 0);
foreach (System.IO.FileInfo _pfile in fi)
{
System.Data.DataRow[] rs = dt.Select("jpegName='" + _pfile.Name.ToString().Trim() + @"'");
if (rs.Length ==0)
{
list.Add(_pfile.Name.ToString().Trim());
}
}
if (list.Count == 0) { UtilityClass.SetMessage("没有图片需要上传", this); return; }
_count = list.Count;
xh_pDialog = new ProgressDialog(this);
xh_pDialog.SetProgressStyle(ProgressDialogStyle.Horizontal);//长方形进度条
xh_pDialog.SetTitle("提示");
xh_pDialog.SetMessage("图片正在上传中,请等候……");
xh_pDialog.Max = _count;
xh_pDialog.SetCancelable(true);//按返回键取消
xh_pDialog.Show();
System.Threading.Thread thread = null;
thread = new System.Threading.Thread(new ThreadStart(progress));
thread.Start();
}
/// <summary>
/// 线程上传
/// </summary>
private void progress()
{
try
{
while (m_count <= _count)
{
xh_pDialog.Progress = m_count++; System.Threading.Thread.Sleep(100);
try
{
bool ret = swe.UploadJpegFile(BitmapBytes(BitmapHelpers.LoadAndResizeBitmap(di + "/" +list[m_count-1].ToString().Trim(), 800, 600)), ID, list[m_count-1].ToString().Trim());
if (!ret)
{
int q = int.Parse("abc");
break;
}
UtilityClass.DeleteJpeg(ID, list[m_count - 1].ToString().Trim());
}
catch (System.Exception)
{
throw;
}
}
xh_pDialog.Cancel();
}
catch (System.Exception)
{
xh_pDialog.Cancel();
return;
}
}