using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.Windows.Forms;
|
using Pub_Class;
|
|
namespace OAM
|
{
|
public partial class frmGGView2 : Form
|
{
|
public frmGGView2()
|
{
|
InitializeComponent();
|
}
|
|
public const int HFileNameCol = 0;//huan
|
public const int HFilePathCol = 1;
|
public const int HUpManCol = 2;
|
public const int HItemIDCol = 3;
|
public long ID;
|
public long MainID;
|
|
public const string ModName = "4507"; //单据类型
|
public const string ModCaption = "行政公告"; //单据名称
|
public const string ModRightName = "frmGGView2";
|
public const string ModRightNameEdit = ModRightName + "_Edit";
|
public const string ModRightNameCheck = ModRightName + "_Check";
|
public const string ModRightNameClose = ModRightName + "_Close";
|
public const string ModRightNameDelete = ModRightName + "_Delete";
|
public bool BillChange; //单据修改状态
|
//
|
public DBUtility.ClsPub.Enum_BillStatus BillStatus; //单据状态(新增,修改,浏览,更新单价,变更)
|
public Int64 KeyID; //单据主内码
|
public bool grdStatus; //网格状态(不可编辑,可编辑)
|
//-------------------------------------------------------------------------
|
|
|
#region 固定代码
|
|
|
//窗体加载
|
private void frmGGView2_Load(object sender, EventArgs e)
|
{
|
initGridFJ();
|
this.Text = ModCaption; //命名窗体标题
|
this.lblCaption.Text = ModCaption;//命名单据标题
|
}
|
|
//主界面删除按钮
|
private void Command1_Click(object sender, EventArgs e)
|
{
|
DialogResult dr = MessageBox.Show("确定要删除此单据吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
if (dr == DialogResult.Yes)
|
{
|
if (!DBUtility.ClsPub.Security_Log("OA_Manager", 1, true, DBUtility.ClsPub.CurUserName))
|
{
|
return;
|
}
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
oCn.RunProc("delete from oa_gg2sub where Mainid=" + ID);
|
oCn.RunProc("delete from oa_gg2 where id=" + ID);
|
MessageBox.Show("删除成功!");
|
this.Close();
|
}
|
else
|
{
|
}
|
|
}
|
|
//添加按钮
|
private void cmdAdd_Click(object sender, EventArgs e)
|
{
|
OpenFileDialog oDlg = new OpenFileDialog();
|
oDlg.Filter = "所有文件|*.*";
|
if (oDlg.ShowDialog() == DialogResult.OK)
|
{
|
if (oDlg.FileName != "")
|
{
|
grdFJ.Rows.Add();
|
grdFJ.Rows[grdFJ.Rows.Count - 1].Cells[HFileNameCol].Value = oDlg.SafeFileName;
|
grdFJ.Rows[grdFJ.Rows.Count - 1].Cells[HFilePathCol].Value = oDlg.FileName;
|
grdFJ.Rows[grdFJ.Rows.Count - 1].Cells[HUpManCol].Value = DBUtility.ClsPub.CurUserName;
|
//直接上传
|
BLL.ClsXt_FileCtrl oFile = new BLL.ClsXt_FileCtrl();
|
if (oFile.LoadUpFile(ID, 1, DBUtility.ClsPub.isStrNull(grdFJ.Rows[grdFJ.Rows.Count - 1].Cells[HFilePathCol].Value), 0,
|
DBUtility.ClsPub.isStrNull(grdFJ.Rows[grdFJ.Rows.Count - 1].Cells[HFileNameCol].Value), DBUtility.ClsPub.CurUserName) == false)
|
{
|
MessageBox.Show("上传文件时失败!");
|
}
|
//
|
}
|
}
|
}
|
|
//删除按钮
|
private void cmdDel_Click(object sender, EventArgs e)
|
{
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
|
if (grdFJ.CurrentRow == null)
|
{
|
|
return;
|
}
|
if (DBUtility.ClsPub.isStrNull(grdFJ.Rows[grdFJ.CurrentRow.Index].Cells[HUpManCol].Value) != DBUtility.ClsPub.CurUserName)
|
{
|
MessageBox.Show("只能删除自己上传的附件!");
|
return;
|
}
|
DialogResult dr = MessageBox.Show("确定要删除此单据吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
if (dr == DialogResult.Yes)
|
{
|
//if (!DBUtility.ClsPub.Security_Log("OA_Manager", 1, true, DBUtility.ClsPub.CurUserName))
|
//{
|
// return;
|
//}
|
//删除附件
|
BLL.ClsXt_FileCtrl oFile = new BLL.ClsXt_FileCtrl();
|
SQLHelper.ClsCNK3 oCNK3 = new SQLHelper.ClsCNK3();
|
if (oFile.DeleteFile(DBUtility.ClsPub.isLong(grdFJ.Rows[grdFJ.CurrentRow.Index].Cells[HItemIDCol].Value), ref DBUtility.ClsPub.sExeReturnInfo, oCNK3) == false)
|
{
|
MessageBox.Show("删除文件时失败!");
|
}
|
//
|
grdFJ.Rows.RemoveAt(grdFJ.CurrentRow.Index);
|
}
|
else
|
{
|
}
|
|
}
|
|
|
//窗体卸载
|
private void frmGGView2_FormClosing(object sender, FormClosingEventArgs e)
|
{
|
BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
|
}
|
|
|
#endregion
|
|
|
#region 读写类
|
//显示单据
|
public void Sub_ShowBill()
|
{
|
|
}
|
|
#endregion
|
|
|
|
public void Display()
|
{
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
DataSet Ds;
|
DataSet Ds2;
|
Ds = oCn.RunProcReturn("Select * from oa_gg2 where id=" + ID, "oa_gg2", ref DBUtility.ClsPub.sExeReturnInfo);
|
if (Ds == null || Ds.Tables[0].Rows.Count == 0)
|
{
|
MessageBox.Show("显示失败!原因:" + DBUtility.ClsPub.sExeReturnInfo);
|
return;
|
}
|
txtZ.Text = Ds.Tables[0].Rows[0]["z"].ToString();
|
txth2.Text = Ds.Tables[0].Rows[0]["h2"].ToString();
|
txtH.Text = Ds.Tables[0].Rows[0]["h"].ToString();
|
txtDesc.Text = Ds.Tables[0].Rows[0]["Description"].ToString();
|
txtTM.Text = Ds.Tables[0].Rows[0]["tm"].ToString();
|
txtEmp.Text = Ds.Tables[0].Rows[0]["emp"].ToString();
|
|
if (Ds.Tables[0].Rows[0]["maker"].ToString() == DBUtility.ClsPub.CurUserName)
|
{
|
cmdSave.Visible = true;
|
}
|
else
|
{
|
cmdSave.Visible = false;
|
}
|
MainID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["MainID"].ToString());
|
|
if (MainID != 0)
|
{
|
oCn.RunProc("update oa_gg2sub set isread=1 where mainid=" + MainID + " and roperator='" + DBUtility.ClsPub.CurUserName + "'");
|
Ds2 = oCn.RunProcReturn("select * from oa_ReadNum where sbill='oa_gg2' and MainID=" + MainID + " and roperator='" + DBUtility.ClsPub.CurUserName + "'", "oa_ReadNum");
|
|
if (Ds!=null&& Ds2.Tables[0].Rows.Count == 0)
|
{
|
oCn.RunProc("insert into oa_ReadNum (MainID,sBill,rOPerator) values (" + MainID + ",'oa_gg2','" + DBUtility.ClsPub.CurUserName + "') ");
|
}
|
}
|
//lblNum.Text = GetReadNum(MainID, "oa_gg2").ToString();
|
txtEmp.Text = GetReadEmp(MainID, "oa_gg2");
|
//附件 huan
|
DisplayFJ();
|
//DBUtility.ClsPub.GetGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);
|
DBUtility.ClsPub.GetGridView(grdFJ, this.Name + "grdFJ", DBUtility.ClsPub.AppPath);
|
//
|
}
|
private void initGridFJ()//huan
|
{
|
grdFJ.ColumnCount = 4; //总列数
|
DBUtility.Xt_BaseBillFun.initGridFst(grdFJ, this.Name + "grdFJ");
|
grdFJ.ReadOnly = true;
|
grdFJ.RowCount = 0;
|
//=
|
grdFJ.Columns[HFileNameCol].HeaderText = "文件名称";
|
grdFJ.Columns[HFilePathCol].HeaderText = "文件路径";
|
grdFJ.Columns[HUpManCol].HeaderText = "上传人";
|
DBUtility.ClsPub.GetGridView(grdFJ, this.Name + "grdFJ", DBUtility.ClsPub.AppPath);
|
}
|
private void DisplayFJ()//huan
|
{
|
SQLHelper.ClsCNK3 oCn = new SQLHelper.ClsCNK3();
|
DataSet Ds;
|
Ds = oCn.RunProcReturn("Select FItemID,fupman,ffilename,fpath from OA_Accessories where FFileID=" + ID, "OA_Accessories");
|
if (Ds == null || Ds.Tables[0].Rows.Count == 0)
|
{
|
return;
|
}
|
for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
|
{
|
grdFJ.Rows.Add();
|
grdFJ.Rows[i].Cells[HFileNameCol].Value = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[i]["FFileName"]);
|
grdFJ.Rows[i].Cells[HFilePathCol].Value = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[i]["FPath"]);
|
grdFJ.Rows[i].Cells[HUpManCol].Value = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[i]["FUpMan"]);
|
grdFJ.Rows[i].Cells[HItemIDCol].Value = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[i]["FItemID"]);
|
}
|
}
|
private string GetReadEmp(long MID, string sBill)
|
{
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
DataSet Ds;
|
string GetReadEmp="";
|
Ds = oCn.RunProcReturn("select roperator from oa_readnum where MainID=" + MID + " and sBill='" + sBill + "'", "oa_readnum");
|
if (Ds == null || Ds.Tables[0].Rows.Count == 0)
|
{
|
GetReadEmp = "";
|
}
|
else
|
{
|
for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
|
{
|
GetReadEmp = GetReadEmp + DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[i][0]) + ",";
|
}
|
}
|
if (GetReadEmp != "")
|
{
|
GetReadEmp = GetReadEmp.Remove(GetReadEmp.Length - 1, 1);
|
}
|
return GetReadEmp;
|
}
|
|
private long GetReadNum(long MID, string sBill)
|
{
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
DataSet Ds;
|
long GetReadNum=0;
|
Ds = oCn.RunProcReturn("select count(*)as Num from oa_readnum where MainID=" + MID + " and sBill='" + sBill + "'", "oa_readnum");
|
if (Ds == null || Ds.Tables[0].Rows.Count == 0)
|
{
|
GetReadNum = 0;
|
}
|
else
|
{
|
GetReadNum = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
|
}
|
return GetReadNum;
|
}
|
|
private void cmdSave_Click(object sender, EventArgs e)
|
{
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
oCn.RunProc("update oa_gg2 set z='" + txtZ.Text + "'" +
|
",h2='" + txth2.Text + "'" +
|
",h='" + txtH.Text + "'" +
|
",Description='" + txtDesc.Text + "'" +
|
",tm='" + txtTM.Text + "'" +
|
",makedate=getdate()" +
|
" where id=" + ID);
|
MessageBox.Show("保存成功");
|
this.Close();
|
}
|
|
private void timer1_Tick(object sender, EventArgs e)
|
{
|
timer1.Enabled = false;
|
Display();
|
}
|
|
private void cmdCancel_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
|
private void grdFJ_DoubleClick(object sender, EventArgs e)
|
{
|
if (grdFJ.CurrentRow == null)
|
{
|
return;
|
}
|
//下载附件到本地,并执行
|
BLL.ClsXt_FileCtrl oFile = new BLL.ClsXt_FileCtrl();
|
SQLHelper.ClsCNK3 oCNK3 = new SQLHelper.ClsCNK3();
|
if (oFile.WriteFile("FFile"
|
, DBUtility.ClsPub.AppPath + @"\a\" + DBUtility.ClsPub.isStrNull(grdFJ.Rows[grdFJ.CurrentRow.Index].Cells[HFileNameCol].Value)
|
, DBUtility.ClsPub.isLong(grdFJ.Rows[grdFJ.CurrentRow.Index].Cells[HItemIDCol].Value), oCNK3) == false)
|
{
|
MessageBox.Show("读取文件时失败!");
|
}
|
System.Diagnostics.Process.Start(DBUtility.ClsPub.AppPath + @"\a\" + DBUtility.ClsPub.isStrNull(grdFJ.Rows[grdFJ.CurrentRow.Index].Cells[HFileNameCol].Value));
|
|
}
|
|
|
}
|
}
|