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 CoreFS.CA06;
using Infragistics.Win.UltraWinEditors;
using Core.Mes.Client.Comm.Control;
using Infragistics.Win.UltraWinGrid;
using Core.Mes.Client.Comm.Tool;
using Core.Mes.Client.Comm.Server;
using CoreFS.SA06;
using System.Collections;
using Infragistics.Win;
using System.IO;
using Pur.Entity;
using com.hnshituo.pur.vo;
using Pur.configure;
using Pur.PublicTools;
using Pur.Pop_upWindow;
namespace Pur
{
public partial class FrmSignature : FrmPmsBase
{
public FrmSignature()
{
InitializeComponent();
}
private void FrmSignature_Load(object sender, EventArgs e)
{
DoQuery("");
GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new String[] { "ownername", "CERTPATH", "CERTDESC", "CHK" });
}
///
/// 重写基类方法
///
///
///
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
DoQuery("");
break;
case "Add":
DoSave();
break;
case "Delete":
DoDelete();
break;
case "Close":
this.Close();
break;
}
}
private void DoQuery(String strID)
{
Signature sg = new Signature();
sg.Validflag = "1";
DataTable dt = this.execute("com.hnshituo.pur.configure.service.SignatureService", "get_Signature", new object[] { sg});
GridHelper.CopyDataToDatatable(dt, this.dataTable1, true);
foreach (UltraGridRow ugr in ultraGrid1.Rows)
{
ugr.Cells["orgId"].Appearance.BackColor =Color.Transparent;
ugr.Cells["orgId"].Appearance.BackHatchStyle = BackHatchStyle.Default;
ugr.Cells["orgId"].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;
}
if (String.IsNullOrEmpty(strID))
{
publicPms.doActiveSelRow(ultraGrid1,"id",strID);
}
}
private void DoSave()
{
ultraGrid1.UpdateData();
ArrayList list = new ArrayList();
string strid = "";
//int count = 0;
IQueryable uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
if (uGrid.Count() == 0)
{
MessageUtil.ShowTips("请选择要新增的数据!");
return;
}
foreach (UltraGridRow ugr in uGrid)
{
String id = ugr.Cells["id"].Value.ToString().Trim();
strid = id;
String orgId = ugr.Cells["orgId"].Value.ToString().Trim();
String orgName = ugr.Cells["orgName"].Value.ToString().Trim();
String ownerUserid = ugr.Cells["ownerUserid"].Value.ToString().Trim();
String ownerName = ugr.Cells["ownerName"].Value.ToString().Trim();
String certDesc = ugr.Cells["certDesc"].Value.ToString().Trim();
if (orgId == "") { MessageUtil.ShowTips("所属部门不能为空!"); return; }
if (orgName == "") { MessageUtil.ShowTips("所属部门不能为空!"); return; }
if (ownerUserid == "") { MessageUtil.ShowTips("所属人不能为空!"); return; }
if (ownerName == "") { MessageUtil.ShowTips("所属人不能为空!"); return; }
Signature sg = new Signature();
sg.Validflag = "1";
sg.OwnerUserid = ownerUserid;
int count = this.execute("com.hnshituo.pur.configure.service.SignatureService", "count", new object[] { sg });
if (count <= 0) { MessageUtil.ShowTips("不存在用户:" + ownerName + "签名数据信息,不能进行此操作,请先上传签名文件!"); return; }
Signature sig = new Signature();
sig.Id = id;
sig.CertDesc = certDesc;
sig.OrgId = orgId;
sig.OrgName = orgName;
sig.OwnerName = ownerName;
sig.OwnerUserid = ownerUserid;
sig.UpdateUserid = UserInfo.GetUserID();
sig.UpdateName = UserInfo.GetUserName();
sig.UpdateTime = DateTime.Now;
list.Add(sig);
//}
}
if (list.Count <= 0)
{
MessageUtil.ShowTips("请选择要新增的数据!");
return;
}
if (MessageUtil.ShowYesNoAndQuestion("是否保存签名?") == System.Windows.Forms.DialogResult.No) return;
CoreResult crt = this.execute("com.hnshituo.pur.configure.service.SignatureService", "do_Save", new object[] { list });
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("保存失败:"+crt.Resultmsg);
return;
}
MessageUtil.ShowTips("操作成功");
DoQuery(strid);
}
private void DoDelete()
{
ultraGrid1.UpdateData();
ArrayList pram = new ArrayList();
IQueryable uGrid = ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
if (uGrid.Count() == 0)
{
MessageUtil.ShowTips("请选择要删除的数据!");
return;
}
if (MessageUtil.ShowYesNoAndQuestion("是否确认删除签名文件?") != DialogResult.Yes)
{
return;
}
foreach (UltraGridRow ugr in uGrid)
{
string craftFilePathOld = ugr.Cells["certPathOld"].Text;
if (FileHelper.Delete(craftFilePathOld) == false)
{
MessageUtil.ShowWarning("删除签名文件失败,请重试!");
return;
}
pram.Add(ugr.Cells["id"].Value.ToString());
}
if (MessageUtil.ShowYesNoAndQuestion("是否删除签名?")!= DialogResult.Yes) return;
CoreResult crt = this.execute("com.hnshituo.pur.configure.service.SignatureService", "do_Delete", new object[] { pram });
if (crt.Resultcode !=0)
{
MessageUtil.ShowTips("删除成功!");
}
else
{
MessageUtil.ShowTips("删除失败:"+crt.Resultmsg); return;
}
DoQuery("");
}
///
/// 上传
///
///
///
private void craftImg_EditorButtonClick(object sender, EditorButtonEventArgs e)
{
UltraGridRow ugr = ultraGrid1.ActiveRow;
string ownerid = ugr.GetValue("OWNERUSERID");
string id = ugr.GetValue("id");
String orgId = ugr.Cells["orgId"].Value.ToString().Trim();
String orgName = ugr.Cells["orgName"].Value.ToString().Trim();
String ownerUserid = ugr.Cells["ownerUserid"].Value.ToString().Trim();
String ownerName = ugr.Cells["ownerName"].Value.ToString().Trim();
String certPath = ugr.Cells["certPath"].Value.ToString().Trim();
String certPathOld = ugr.Cells["certPathOld"].Value.ToString().Trim();
String certDesc = ugr.Cells["certDesc"].Value.ToString().Trim();
//String filePathOld = "PMS/Signature/" + ownerid + "/";
if (e.Button.Key.ToLower().Equals("select"))
{
FrmPopFileShow down = new FrmPopFileShow(this.ob, certPathOld);
down.DeleteButton.Visible = false;
down.ShowDialog();
}
if (e.Button.Key.ToLower().Equals("insert"))
{
String fileName = "";
String filena = "";
if (String.IsNullOrEmpty(ownerid))
{
MessageUtil.ShowTips("没有所属人员id不允许上传,请先选择人员信息!");
return;
}
OpenFileDialog file = new OpenFileDialog();
file.Multiselect = false;
DialogResult drStat;
drStat = file.ShowDialog();
if (drStat == DialogResult.OK)
{
fileName = file.FileName;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
long s = fs.Length;
if (s / 1024.0 > 20)
{
MessageUtil.ShowTips("图片大于20KB,请重新上传!");
return;
}
String filePathlocal = System.IO.Path.GetFullPath(fileName);
filena = System.IO.Path.GetFileName(fileName);
}
if (ultraGrid1.ActiveRow == null)
{
MessageUtil.ShowTips("未选择签名项");
return;
}
if (String.IsNullOrEmpty(filena) || String.IsNullOrEmpty(fileName))
{
MessageUtil.ShowTips("请选择待上传文件");
return;
}
Signature sat = new Signature();
sat.OwnerUserid = ownerid;
String filePathNew = "Pms/Signature/" + ownerid + "/";
sat.CertPath = filena;
sat.CertPathOld = filePathNew + filena;
sat.Id = id;
sat.CertDesc = certDesc;
sat.OrgId = orgId;
sat.OrgName = orgName;
sat.OwnerName = ownerName;
sat.OwnerUserid = ownerUserid;
sat.Image = FileHelper.FileToArray(fileName);
sat.CreateUserid = UserInfo.GetUserID();
sat.CreateName = UserInfo.GetUserName();
sat.CreateTime = DateTime.Now;
sat.Validflag = "1";
if (GetCraftFileCraftNoCnt(filena, ownerid) > 0)
{
MessageUtil.ShowTips("已存在该签名文件:" + filena);
return;
}
List list = new List();
FileBean bean = new FileBean();
bean = new FileBean();
bean.setFileName(filena);
bean.setPathName(filePathNew);
bean.setFile(FileHelper.FileToArray(fileName));
list.Add(bean);
bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
if (isSuccess)
{
CoreResult crt = new CoreResult();
//开始写数据库
if (String.IsNullOrEmpty(id))
{
crt = this.execute("com.hnshituo.pur.configure.service.SignatureService", "do_Insert", new object[] { sat });
}
else
{
crt = this.execute("com.hnshituo.pur.configure.service.SignatureService", "do_Update", new object[] { sat });
}
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("上传失败:" + crt.Resultmsg);
}
else
{
MessageUtil.ShowTips("上传成功");
DoQuery(crt.Resultmsg);
}
}
else
{
MessageBox.Show("上传失败");
}
}
}
///
/// 判断是否之前已提交相同的文件
///
///
///
private int GetCraftFileCraftNoCnt(string CERT_PATH, string OwnerUserid)
{
Signature sat = new Signature();
sat.CertPath = CERT_PATH;
sat.OwnerUserid = OwnerUserid;
sat.Validflag = "1";
int dt = this.execute("com.hnshituo.pur.configure.service.SignatureService", "count", new object[] { sat });
return dt;
}
private void ultraGrid1_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
{
try
{
ultraGrid1.UpdateData();
foreach (UltraGridRow r in ultraGrid1.Rows)
{
r.Cells["CHK"].Value = r.Selected;
}
}
catch { }
}
private void txt_selectMan_EditorButtonClick(object sender, EditorButtonEventArgs e)
{
SetectManByDept frm = new SetectManByDept(this.ob);
frm.ShowDialog();
if (frm.strTips == "1")
{
String strdeptId = frm.StrDeptId;
String strDeptName = frm.StrDeptName;
String strUserName = frm.StrUserName;
String strUserId = frm.StrUserID;
if (ultraGrid1.ActiveRow == null)
{
return;
}
else
{
UltraGridRow row = ultraGrid1.ActiveRow;
row.Cells["orgId"].Value = strdeptId;
row.Cells["orgName"].Value = strDeptName;
row.Cells["ownername"].Value = strUserName;
row.Cells["ownerUserid"].Value = strUserId;
}
}
}
}
}