提交代码
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using BLL;
|
||||
using BLL.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ThoughtWorks.QRCode.Codec;
|
||||
using AspNet = System.Web.UI.WebControls;
|
||||
|
||||
namespace FineUIPro.Web.HSSE.QualityAudit
|
||||
@@ -294,5 +297,120 @@ namespace FineUIPro.Web.HSSE.QualityAudit
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected void btnQR_Click(object sender, EventArgs e)
|
||||
{
|
||||
string strSql = @"SELECT EquipmentQuality.EquipmentQualityId, CodeRecords.Code AS EquipmentQualityCode,
|
||||
EquipmentQuality.FactoryCode ,EquipmentQuality.QRCodeAttachUrl
|
||||
FROM QualityAudit_EquipmentQuality AS EquipmentQuality
|
||||
LEFT JOIN Sys_CodeRecords AS CodeRecords ON EquipmentQuality.EquipmentQualityId = CodeRecords.DataId
|
||||
LEFT JOIN Base_SpecialEquipment AS SpecialEquipment ON SpecialEquipment.SpecialEquipmentId = EquipmentQuality.SpecialEquipmentId WHERE 1=1 ";
|
||||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
|
||||
{
|
||||
strSql += " AND EquipmentQuality.ProjectId = @ProjectId";
|
||||
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(this.txtEquipmentQualityCode.Text.Trim()))
|
||||
{
|
||||
strSql += " AND EquipmentQualityCode LIKE @EquipmentQualityCode";
|
||||
listStr.Add(new SqlParameter("@EquipmentQualityCode", "%" + this.txtEquipmentQualityCode.Text.Trim() + "%"));
|
||||
}
|
||||
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
|
||||
{
|
||||
strSql += " AND EquipmentQuality.UnitId = @UnitId";
|
||||
listStr.Add(new SqlParameter("@UnitId", this.drpUnitId.SelectedValue.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(this.txtSpecialEquipmentName.Text.Trim()))
|
||||
{
|
||||
strSql += " AND SpecialEquipmentName LIKE @SpecialEquipmentName";
|
||||
listStr.Add(new SqlParameter("@SpecialEquipmentName", "%" + this.txtSpecialEquipmentName.Text.Trim() + "%"));
|
||||
}
|
||||
SqlParameter[] parameter = listStr.ToArray();
|
||||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||||
|
||||
NPOIExcel excel = new NPOIExcel();
|
||||
excel.SetColumnWidth(0, 50);
|
||||
excel.SetColumnWidth(1, 50);
|
||||
excel.SetColumnWidth(2, 50);
|
||||
for (int i = 0; i < tb.Rows.Count; i++)
|
||||
{
|
||||
if (i % 3 == 0)
|
||||
{
|
||||
excel.SetRowHeight(2 * (int)(i / 3), 200);
|
||||
}
|
||||
string QRCodeAttachUrl = tb.Rows[i]["QRCodeAttachUrl"].ToString();
|
||||
string EquipmentQualityCode = tb.Rows[i]["EquipmentQualityCode"].ToString();
|
||||
if (string.IsNullOrEmpty(QRCodeAttachUrl))
|
||||
{
|
||||
try
|
||||
{
|
||||
var equipmentQuality = Funs.DB.QualityAudit_EquipmentQuality.FirstOrDefault(x => x.EquipmentQualityId == tb.Rows[i]["EquipmentQualityId"].ToString());
|
||||
equipmentQuality.QRCodeAttachUrl = CreateCode_Simple("equipment$" + tb.Rows[i]["FactoryCode"].ToString());
|
||||
QRCodeAttachUrl = equipmentQuality.QRCodeAttachUrl;
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
catch (Exception e1) { }
|
||||
|
||||
}
|
||||
//add picture data to this workbook.
|
||||
excel.SetPicValue(2 * (int)(i / 3), i % 3, Server.MapPath("~/") + QRCodeAttachUrl);
|
||||
excel.SetValue(2 * (int)(i / 3) + 1, i % 3, EquipmentQualityCode);
|
||||
}
|
||||
string initTemplatePath = Const.ExcelUrl + Funs.GetNewFileName() + ".xls";
|
||||
string uploadfilepath = Server.MapPath("~/") + initTemplatePath;
|
||||
string fileName = Path.GetFileName(initTemplatePath);
|
||||
excel.Save(uploadfilepath);
|
||||
FileInfo info = new FileInfo(uploadfilepath);
|
||||
|
||||
long fileSize = info.Length;
|
||||
Response.ClearContent();
|
||||
Response.ContentType = "application/x-zip-compressed";
|
||||
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
||||
Response.AddHeader("Content-Length", fileSize.ToString());
|
||||
Response.TransmitFile(uploadfilepath, 0, fileSize);
|
||||
Response.Flush();
|
||||
Response.End();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private string CreateCode_Simple(string nr)
|
||||
{
|
||||
try
|
||||
{
|
||||
string imageUrl = string.Empty;
|
||||
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder
|
||||
{
|
||||
QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE,
|
||||
QRCodeScale = nr.Length,
|
||||
QRCodeVersion = 0,
|
||||
QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M
|
||||
};
|
||||
System.Drawing.Image image = qrCodeEncoder.Encode(nr, Encoding.UTF8);
|
||||
string filepath = Server.MapPath("~/") + UploadFileService.QRCodeImageFilePath;
|
||||
//如果文件夹不存在,则创建
|
||||
if (!Directory.Exists(filepath))
|
||||
{
|
||||
Directory.CreateDirectory(filepath);
|
||||
}
|
||||
string filename = DateTime.Now.ToString("yyyymmddhhmmssfff").ToString() + ".jpg";
|
||||
imageUrl = filepath + filename;
|
||||
FileStream fs = new FileStream(imageUrl, FileMode.OpenOrCreate, FileAccess.Write);
|
||||
image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
fs.Close();
|
||||
image.Dispose();
|
||||
return UploadFileService.QRCodeImageFilePath + filename;
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
|
||||
{
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user