453 lines
18 KiB
C#
453 lines
18 KiB
C#
using System;
|
||
using System.Linq;
|
||
using System.Drawing;
|
||
using ThoughtWorks.QRCode.Codec;
|
||
using ThoughtWorks.QRCode.Codec.Data;
|
||
using System.Text;
|
||
using System.IO;
|
||
using BLL;
|
||
|
||
namespace FineUIPro.Web.common.WelderManage
|
||
{
|
||
public partial class WelderManageEdit : PageBase
|
||
{
|
||
#region 定义变量
|
||
/// <summary>
|
||
/// 照片附件路径
|
||
/// </summary>
|
||
public string PhotoAttachUrl
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["PhotoAttachUrl"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["PhotoAttachUrl"] = value;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 二维码路径id
|
||
/// </summary>
|
||
public string QRCodeAttachUrl
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["QRCodeAttachUrl"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["QRCodeAttachUrl"] = value;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 加载
|
||
/// <summary>
|
||
/// 加载页面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
|
||
BLL.Base_UnitService.InitUnitDropDownList(this.drpUnit, true, BLL.Const.UnitType_5, Resources.Lan.PleaseSelect);//单位
|
||
BLL.Base_ProjectTypeService.InitProjectTypeDropDownList(this.drpPojectType, true, Resources.Lan.PleaseSelect);//项目类型
|
||
|
||
string welderId = Request.Params["welderId"];
|
||
string unitId = Request.Params["unitId"];
|
||
if (!string.IsNullOrEmpty(welderId))
|
||
{
|
||
Model.Welder_Welder welder = BLL.WelderService.GetWelderById(welderId);
|
||
if (welder != null)
|
||
{
|
||
this.txtWelderCode.Text = welder.WelderCode;
|
||
this.txtWelderName.Text = welder.WelderName;
|
||
if (!string.IsNullOrEmpty(welder.UnitId))
|
||
{
|
||
drpUnit.SelectedValue = welder.UnitId;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(welder.ProjectTypeId))
|
||
{
|
||
this.drpPojectType.SelectedValue = welder.ProjectTypeId;
|
||
}
|
||
|
||
this.rblSex.SelectedValue = welder.Sex;
|
||
|
||
if (welder.Birthday.HasValue)
|
||
{
|
||
this.txtBirthday.Text = string.Format("{0:yyyy-MM-dd}", welder.Birthday);
|
||
}
|
||
this.txtIdentityCard.Text = welder.IdentityCard;
|
||
this.txtCertificateNum.Text = welder.CertificateNum;
|
||
if (welder.CertificateValidity.HasValue)
|
||
{
|
||
this.txtCertificateValidity.Text = string.Format("{0:yyyy-MM-dd}", welder.CertificateValidity);
|
||
}
|
||
this.txtWelderLevel.Text = welder.WelderLevel;
|
||
if (welder.IsOnDuty == true)
|
||
{
|
||
cbIsOnDuty.Checked = true;
|
||
}
|
||
else
|
||
{
|
||
cbIsOnDuty.Checked = false;
|
||
}
|
||
this.txtRemark.Text = welder.Remark;
|
||
if (!string.IsNullOrEmpty(welder.PhotoUrl))
|
||
{
|
||
this.PhotoAttachUrl = welder.PhotoUrl;
|
||
this.Image1.ImageUrl = "~/" + this.PhotoAttachUrl;
|
||
}
|
||
if (!string.IsNullOrEmpty(welder.QRCodeAttachUrl))
|
||
{
|
||
this.QRCodeAttachUrl = welder.QRCodeAttachUrl;
|
||
this.btnSee.Hidden = false;
|
||
this.btnQR.Hidden = false;
|
||
this.btnQR.Text = "二维码重新生成";
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.cbIsOnDuty.Checked = true;
|
||
if (!string.IsNullOrEmpty(unitId))
|
||
{
|
||
drpUnit.SelectedValue = unitId;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 保存
|
||
/// <summary>
|
||
/// 保存按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
string welderId = Request.Params["WelderId"];
|
||
var q = Funs.DB.Welder_Welder.FirstOrDefault(x => x.WelderCode == this.txtWelderCode.Text.Trim()
|
||
&& (x.WelderId != welderId || (welderId == null && welderId != null)));
|
||
if (q != null)
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.WelderCodeExists, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
if (this.drpPojectType.SelectedValue == BLL.Const._Null)
|
||
{
|
||
ShowNotify(Resources.Lan.PleaseSelect + Resources.Lan.ProjectType + "!", MessageBoxIcon.Success);
|
||
return;
|
||
}
|
||
|
||
if (drpUnit.SelectedValue == BLL.Const._Null)
|
||
{
|
||
ShowNotify("请选择单位!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
welderId = SaveData(welderId);
|
||
ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success);
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
||
}
|
||
|
||
private string SaveData(string welderId)
|
||
{
|
||
Model.Welder_Welder newWelder = new Model.Welder_Welder();
|
||
newWelder.WelderCode = this.txtWelderCode.Text.Trim();
|
||
newWelder.WelderName = this.txtWelderName.Text.Trim();
|
||
newWelder.UnitId = drpUnit.SelectedValue;
|
||
newWelder.Sex = this.rblSex.SelectedValue;
|
||
newWelder.Birthday = Funs.GetNewDateTime(this.txtBirthday.Text.Trim());
|
||
newWelder.IdentityCard = this.txtIdentityCard.Text.Trim();
|
||
newWelder.CertificateNum = this.txtCertificateNum.Text.Trim();
|
||
newWelder.ProjectTypeId = this.drpPojectType.SelectedValue;
|
||
newWelder.CertificateValidity = Funs.GetNewDateTime(this.txtCertificateValidity.Text.Trim());
|
||
newWelder.WelderLevel = this.txtWelderLevel.Text.Trim();
|
||
if (this.cbIsOnDuty.Checked)
|
||
{
|
||
newWelder.IsOnDuty = true;
|
||
}
|
||
else
|
||
{
|
||
newWelder.IsOnDuty = false;
|
||
}
|
||
newWelder.Remark = this.txtRemark.Text.Trim();
|
||
newWelder.PhotoUrl = this.PhotoAttachUrl;
|
||
if (!string.IsNullOrEmpty(welderId))
|
||
{
|
||
if (!BLL.WelderService.IsExisWelderCode(welderId, this.txtWelderCode.Text))
|
||
{
|
||
newWelder.WelderId = welderId;
|
||
if (!BLL.WelderService.IsExisIdentityCard(welderId, this.txtIdentityCard.Text))
|
||
{
|
||
BLL.WelderService.UpdateWelder(newWelder);
|
||
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WelderManageMenuId, Const.BtnModify, welderId);
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent(Resources.Lan.IsExistIdentityCard, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
{
|
||
Alert.ShowInParent(Resources.Lan.WelderCodeExists, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
welderId = SQLHelper.GetNewID(typeof(Model.Welder_Welder));
|
||
if (!BLL.WelderService.IsExisWelderCode(welderId, this.txtWelderCode.Text))
|
||
{
|
||
if (!BLL.WelderService.IsExisIdentityCard(welderId, this.txtIdentityCard.Text))
|
||
{
|
||
newWelder.WelderId = welderId;
|
||
BLL.WelderService.AddWelder(newWelder);
|
||
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WelderManageMenuId, Const.BtnAdd, welderId);
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent(Resources.Lan.IsExistIdentityCard, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent(Resources.Lan.WelderCodeExists, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
return welderId;
|
||
}
|
||
#endregion
|
||
|
||
protected void drpPojectType_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
string welderId = Request.Params["WelderId"];
|
||
if (string.IsNullOrEmpty(welderId))
|
||
{
|
||
string maxCode = string.Empty;
|
||
string str = string.Empty;
|
||
string num = string.Empty;
|
||
|
||
string bigProjectId = string.Empty;
|
||
var bigProject = from x in Funs.DB.Base_ProjectType where x.ProjectTypeName.Contains("大项目") select x;
|
||
if (bigProject.Count() > 0)
|
||
{
|
||
bigProjectId = bigProject.First().ProjectTypeId;
|
||
}
|
||
var isExistProjectType = from x in Funs.DB.Project_Unit
|
||
join z in Funs.DB.Base_Project on x.ProjectId equals z.ProjectId
|
||
where x.UnitId == drpUnit.SelectedValue
|
||
&& z.ProjectTypeId == this.drpPojectType.SelectedValue
|
||
select x;
|
||
if (isExistProjectType.Count() > 0)
|
||
{
|
||
var welder = from x in Funs.DB.Welder_Welder select x;
|
||
if (this.drpPojectType.SelectedText.Contains("大项目"))
|
||
{
|
||
welder = welder.Where(x => x.ProjectTypeId == bigProjectId && x.WelderCode.Contains("K")).OrderByDescending(x => x.WelderCode);
|
||
}
|
||
else
|
||
{
|
||
welder = welder.Where(x => x.ProjectTypeId != bigProjectId && x.WelderCode.Contains("A")).OrderByDescending(x => x.WelderCode);
|
||
}
|
||
//var welder = from x in Funs.DB.Welder_Welder where x.ProjectTypeId == this.drpPojectType.SelectedValue orderby x.WelderCode descending select x;
|
||
if (welder.Count() > 0)
|
||
{
|
||
maxCode = welder.First().WelderCode;
|
||
str = maxCode.Substring(0, 1);
|
||
num = maxCode.Substring(1);
|
||
if (num == "999")
|
||
{
|
||
// 获取一个字母
|
||
str = (Convert.ToChar(Convert.ToInt16(str.ToCharArray()[0]) + 1)).ToString();
|
||
num = "001";
|
||
}
|
||
else
|
||
{
|
||
num = Funs.GetThreeNumber(num);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (drpPojectType.SelectedText.Contains("大项目"))
|
||
{
|
||
str = "K";
|
||
num = "001";
|
||
}
|
||
else
|
||
{
|
||
str = "A";
|
||
num = "001";
|
||
}
|
||
}
|
||
this.txtWelderCode.Text = str + num;
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop("该单位没有参与" + drpPojectType.SelectedText + "!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var welder = BLL.WelderService.GetWelderById(welderId);
|
||
this.txtWelderCode.Text = welder.WelderCode;
|
||
}
|
||
}
|
||
|
||
|
||
#region 附件上传
|
||
/// <summary>
|
||
/// 上传附件资源
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnAttachUrl_Click(object sender, EventArgs e)
|
||
{
|
||
string edit = "0";
|
||
string welderId = Request.Params["WelderId"];
|
||
if (string.IsNullOrEmpty(welderId))
|
||
{
|
||
SaveData(welderId);
|
||
}
|
||
else
|
||
{
|
||
edit = "1";
|
||
}
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/WelderManage&menuId={1}&edit={2}", welderId, BLL.Const.WelderManageMenuId, edit)));
|
||
}
|
||
#endregion
|
||
|
||
#region 照片上传
|
||
/// <summary>
|
||
/// 上传照片
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnPhoto_Click(object sender, EventArgs e)
|
||
{
|
||
if (filePhoto.HasFile)
|
||
{
|
||
string fileName = filePhoto.ShortFileName;
|
||
|
||
if (!ValidateFileType(fileName))
|
||
{
|
||
ShowNotify(Resources.Lan.InvalidFileType, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
this.PhotoAttachUrl = BLL.UploadFileService.UploadAttachment(BLL.Funs.RootPath, this.filePhoto, this.PhotoAttachUrl, Const.WelderFilePath);
|
||
this.Image1.ImageUrl = "~/" + this.PhotoAttachUrl;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
protected void btnQR_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(this.txtWelderCode.Text.Trim()))
|
||
{
|
||
Alert.ShowInTop("焊工证不能为空!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
this.CreateCode_Simple(this.txtWelderCode.Text.Trim());
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSee_Click(object sender, EventArgs e)
|
||
{
|
||
string url = string.Empty;
|
||
string welderId = Request.Params["WelderId"];
|
||
Model.Welder_Welder welder = BLL.WelderService.GetWelderById(welderId);
|
||
|
||
if (welder != null && !string.IsNullOrEmpty(welder.QRCodeAttachUrl))
|
||
{
|
||
url = welder.QRCodeAttachUrl;
|
||
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("SeeQRImage.aspx?WelderId={0}", welderId), "二维码查看", 400, 400));
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop("二维码不存在!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
//生成二维码方法一
|
||
private void CreateCode_Simple(string nr)
|
||
{
|
||
string welderId = Request.Params["WelderId"];
|
||
|
||
Model.Welder_Welder welder = BLL.WelderService.GetWelderById(welderId);
|
||
if (welder != null)
|
||
{
|
||
BLL.UploadFileService.DeleteFile(Funs.RootPath, welder.QRCodeAttachUrl);//删除二维码
|
||
string imageUrl = string.Empty;
|
||
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
|
||
qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
|
||
qrCodeEncoder.QRCodeScale = nr.Length;
|
||
qrCodeEncoder.QRCodeVersion = 0;
|
||
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
|
||
System.Drawing.Image image = qrCodeEncoder.Encode(nr, Encoding.UTF8);
|
||
|
||
string filepath = Server.MapPath("~/") + BLL.UploadFileService.QRCodeImageFilePath;
|
||
|
||
//如果文件夹不存在,则创建
|
||
if (!Directory.Exists(filepath))
|
||
{
|
||
Directory.CreateDirectory(filepath);
|
||
}
|
||
|
||
string filename = DateTime.Now.ToString("yyyymmddhhmmssfff").ToString() + ".jpg";
|
||
imageUrl = filepath + filename;
|
||
|
||
System.IO.FileStream fs = new System.IO.FileStream(imageUrl, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
|
||
image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
|
||
fs.Close();
|
||
image.Dispose();
|
||
this.QRCodeAttachUrl = BLL.UploadFileService.QRCodeImageFilePath + filename;
|
||
|
||
BLL.WelderService.UpdateQRCode(welderId, QRCodeAttachUrl);
|
||
this.btnSee.Hidden = false;
|
||
this.btnQR.Hidden = false;
|
||
this.btnQR.Text = "二维码重新生成";
|
||
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("SeeQRImage.aspx?WelderId={0}", welderId), "二维码查看", 400, 400));
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop("操作有误,重新生成!", MessageBoxIcon.Warning);
|
||
}
|
||
|
||
//二维码解码
|
||
//var codeDecoder = CodeDecoder(filepath);
|
||
|
||
//this.Image1.ImageUrl = "~/image/" + filename + ".jpg";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 二维码解码
|
||
/// </summary>
|
||
/// <param name="filePath">图片路径</param>
|
||
/// <returns></returns>
|
||
public string CodeDecoder(string filePath)
|
||
{
|
||
//if (!System.IO.File.Exists(filePath))
|
||
// return null;
|
||
//Bitmap myBitmap = new Bitmap(Image.FromFile(filePath));
|
||
//QRCodeDecoder decoder = new QRCodeDecoder();
|
||
//string decodedString = decoder.decode(new QRCodeBitmapImage(myBitmap));
|
||
//return decodedString;
|
||
return "";
|
||
}
|
||
}
|
||
} |