12,162
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 上传图片
/// </summary>
/// <param name="caseid">案件号</param>
/// <param name="twoid">车编号、人编号</param>
/// <param name="pic">压缩后二进制格式的图片</param>
/// <param name="picmemo">图片备注</param>
/// <param name="tablename">存储在数据库中的表名</param>
/// <param name="filedname">单证类型</param>
/// <param name="exifTime">EXIF信息</param>
/// <returns></returns>
public string CaseUpLoadImage(string caseid, int twoid, byte[] pic,
string picmemo, string tablename, string filedname,
string exifTime)
{
try
{
MyFrame.Base.CompressionHelper ch = new CompressionHelper();
byte[] images = ch.DecompressToBytes(pic); //解压
MemoryStream ms = new MemoryStream(images);
Bitmap img = new Bitmap(ms);
string picTmpFilesPath = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
string picTmpFiles = picTmpFilesPath + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".jpg";
picTmpFilesPath = Server.MapPath("~/uploadfiles/" + picTmpFilesPath);
if (!Directory.Exists(picTmpFilesPath))
{
Directory.CreateDirectory(picTmpFilesPath);
}
picTmpFilesPath = picTmpFilesPath + @"\" + picTmpFiles;
img.Save(picTmpFilesPath);
DataOperation mydo = new DataOperation();
string strsql = "";
if (filedname != "")
{
strsql = "Insert into " + tablename + "(TWOID,CASEID,PICPATH,NOTE,ADDDATE,DZCLASS,EXIFTIME)"
+ " values (" + twoid + ",'" + caseid + "','" + picTmpFilesPath + "','" + picmemo
+ "',to_date('" + DateTime.Now.ToString() + "','yyyy-mm-dd hh24-mi-ss'),'" + filedname + "','" + exifTime + "')";
}
else
{
strsql = "Insert into " + tablename + "(TWOID,CASEID,PICPATH,NOTE,ADDDATE,EXIFTIME)"
+ " values (" + twoid + ",'" + caseid + "','" + picTmpFilesPath + "','" + picmemo
+ "',to_date('" + DateTime.Now.ToString() + "','yyyy-mm-dd hh24-mi-ss'),'" + exifTime + "')";
}
if (!mydo.SetExeSql(strsql))
{
return mydo.ErrInfo;
}
return "1";
}
catch (Exception ex)
{
return ex.Message;
}
}
private void c_OnShangChuan(object sender, EventArgs e)
{
UpLoadPic[] abc = uploadimages1.FileNames;
uploadimages1.ProgressBarMax = abc.Length;
string a = ""; string b = "";
for (int i = 0; i < abc.Length; i++)
{
a = abc[i].path;
b = abc[i].exifTime;
Bitmap bmp = new Bitmap(a);
string aa = sc.CaseUpLoadImage(caseid, TwoId,
ImageGdi(bmp), "", imagePath, DzClass,b);
if (aa != "1")
{
uploadimages1.AddSangChuanInfo(aa);
}
else
{
uploadimages1.ProgressBarStep(i+1);
uploadimages1.AddSangChuanInfo(string.Format("上传{0}图片成功!",abc[i].path));
}
Application.DoEvents();
}
uploadimages1.AddSangChuanInfo("----------------------------");
uploadimages1.AddSangChuanInfo("所有图片上传完毕!");
uploadimages1.UpLoadOver();
Application.DoEvents();
}