using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.IO;
|
using System.Data.SqlClient;
|
using System.Windows.Forms;
|
using System.Data;
|
using Pub_Class;
|
|
namespace BLL
|
{
|
public class ClsXt_FileCtrl
|
{
|
|
public Int64 HInterID;
|
public Int64 HFileSize;
|
public string HFileType;
|
public string HPath;
|
public string HFileName;
|
public string HMaker;
|
public DateTime HMakeDate;
|
public string HRemark;
|
//
|
public Int64 HBillID;
|
public string HBillNo;
|
public string HBillType;
|
private string mvarItemKey;
|
public string _sqlConnection;
|
|
//
|
public ClsXt_FileCtrl()
|
{
|
mvarItemKey = "8001";
|
mvarReportTitle = "µ¥¾Ý¸½¼þ";
|
if (DBUtility.ClsPub.isStrNull(DBUtility.ClsPub.AppPath) == "")
|
{
|
DBUtility.ClsPub.AppPath = System.Environment.CurrentDirectory;
|
//ClsPub.AppPath = @"C:\Windows\System32";
|
}
|
string sServer = ClsIni.ReadIni("K32Erp", "Server", ClsPub.AppPath + @"\" + "HXErp.ini");
|
string sDataBase = ClsIni.ReadIni("K32Erp", "DataBase", ClsPub.AppPath + @"\" + "HXErp.ini");
|
string sUser = ClsIni.ReadIni("K32Erp", "UserName", ClsPub.AppPath + @"\" + "HXErp.ini");
|
string sPassword = ClsIni.ReadIni("K32Erp", "PassWord", ClsPub.AppPath + @"\" + "HXErp.ini");
|
_sqlConnection = "Data Source=" + sServer + ";DataBase=" + sDataBase + ";User ID=" + sUser + ";PWD=" + sPassword + ";max pool size=512";
|
//
|
}
|
|
public string MvarItemKey
|
{
|
get { return mvarItemKey; }
|
set { mvarItemKey = value; }
|
}
|
private string mvarReportTitle;
|
|
public string MvarReportTitle
|
{
|
get { return mvarReportTitle; }
|
set { mvarReportTitle = value; }
|
}
|
|
//ѹËõÎļþ
|
public bool CompressFile(string sFilePath, string sTable, string sFieldName, long HInterID, Pub_Class.ClsSqlHelper oCn)
|
{
|
//KDZIP.ZIP oZip = new ZIP();
|
//File.Delete(DBUtility.ClsPub.AppPath + @"\tmpfile");
|
//short iErr = oZip.CompressEx(sFilePath, DBUtility.ClsPub.AppPath + @"\tmpfile", 6);
|
//string sErr = oZip.GetErrorDescription(iErr);
|
//if (sErr.Trim() == "ûÓдíÎó")
|
//{
|
if (LoadUpFile(sTable, sFieldName, sFilePath, HInterID, oCn))
|
{
|
//oZip = null;
|
return true;
|
}
|
else
|
{
|
//oZip = null;
|
return false;
|
}
|
//}
|
//else
|
//{
|
// MessageBox.Show("ѹËõʧ°Ü!");
|
// oZip = null;
|
// return false;
|
//}
|
}
|
|
|
//×÷ÒµÖ¸µ¼ÊéÉÏ´«Í¼Æ¬
|
public bool LoadUpImage(Int64 sHFileID, string sSafeFileName, string sPath)
|
{
|
try
|
{
|
SqlConnection con = new SqlConnection(_sqlConnection);
|
|
con.Open();
|
byte[] FileList = this.FileToByteArray(sPath);
|
string commandText = @" INSERT INTO HX_LCEIFile..Gy_SOPFile (HFileID,HFileName,HFileSize,HFile,HUpTime) " +
|
"VALUES (" + sHFileID + ",'" + sSafeFileName + "',0,@FileList,getdate())";
|
SqlCommand comm = new SqlCommand(commandText, con);
|
comm.Parameters.AddWithValue("@FileList", FileList);
|
comm.ExecuteNonQuery();
|
con.Close();
|
}
|
catch (Exception e)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
|
//ѹËõÎļþA3
|
public bool CompressFile(string sFilePath, string sTable, string sFieldName, string HBillNo, string sType, Pub_Class.ClsSqlHelper oCn)
|
{
|
//KDZIP.ZIP oZip = new ZIP();
|
////File.Delete(DBUtility.ClsPub.AppPath + @"\tmpfile");
|
//short iErr = oZip.CompressEx(sFilePath, DBUtility.ClsPub.AppPath + @"\tmpfile", 6);
|
//string sErr = oZip.GetErrorDescription(iErr);
|
//if (sErr.Trim() == "ûÓдíÎó")
|
//{
|
if (LoadUpFile(sTable, sFieldName, sFilePath, HBillNo, sType, oCn))
|
{
|
//oZip = null;
|
return true;
|
}
|
else
|
{
|
//oZip = null;
|
return false;
|
}
|
//}
|
//else
|
//{
|
// MessageBox.Show("ѹËõʧ°Ü!");
|
// oZip = null;
|
// return false;
|
//}
|
}
|
|
//½âѹËõÎļþ
|
public bool CompressBackFile(string sFilePath, long HInterID, Pub_Class.ClsSqlHelper oCn)
|
{
|
//KDZIP.ZIP oZip = new ZIP();
|
//File.Delete(DBUtility.ClsPub.AppPath + @"\tmpfile2");
|
if (WriteFile("", "HFile", sFilePath, HInterID, oCn))
|
{
|
//short iErr = oZip.DeCompressEx(DBUtility.ClsPub.AppPath + @"\tmpfile2", sFilePath);
|
//string sErr = oZip.GetErrorDescription(iErr);
|
//if (sErr.Trim() == "ûÓдíÎó")
|
//{
|
return true;
|
//}
|
//else
|
//{
|
// MessageBox.Show("½âѹËõʧ°Ü!" + sErr);
|
// return false;
|
//}
|
}
|
else
|
{
|
MessageBox.Show("¶ÁÈ¡Êý¾Ý¿âÎļþʧ°Ü£¡");
|
return false;
|
}
|
}
|
|
//½âѹËõÎļþA3
|
public bool CompressBackFile(string sFilePath, string HBillNo, string sType, Pub_Class.ClsSqlHelper oCn)
|
{
|
//KDZIP.ZIP oZip = new ZIP();
|
//File.Delete(DBUtility.ClsPub.AppPath + @"\tmpfile2");
|
if (WriteFile("", "HFile", sFilePath, HBillNo, sType, oCn))
|
{
|
//short iErr = oZip.DeCompressEx(DBUtility.ClsPub.AppPath + @"\tmpfile2", sFilePath);
|
//string sErr = oZip.GetErrorDescription(iErr);
|
//if (sErr.Trim() == "ûÓдíÎó")
|
//{
|
return true;
|
//}
|
//else
|
//{
|
// MessageBox.Show("½âѹËõʧ°Ü!" + sErr);
|
// return false;
|
//}
|
}
|
else
|
{
|
MessageBox.Show("¶ÁÈ¡Êý¾Ý¿âÎļþʧ°Ü£¡");
|
return false;
|
}
|
}
|
|
//ÉÏ´«ÎļþA3
|
public bool LoadUpFile(Int64 iFileID, int iMainType, string sPath, int sSize, string sFileName, string sUpMan)
|
{
|
try
|
{
|
SqlConnection con = new SqlConnection(_sqlConnection);
|
con.Open();
|
byte[] FileList = this.FileToByteArray(sPath);
|
string commandText = @" INSERT INTO OA_Accessories (FFileID,FMainType,FPath,FFileSize,FFileName,FFile,FUpMan) " +
|
"VALUES (" + iFileID.ToString() + "," + iMainType.ToString() + ",'" + sPath + "'," + sSize.ToString() + ",'" +
|
sFileName + "',@FileList,'" + sUpMan + "')";
|
SqlCommand comm = new SqlCommand(commandText, con);
|
comm.Parameters.AddWithValue("@FileList", FileList);
|
comm.ExecuteNonQuery();
|
con.Close();
|
}
|
catch (Exception e)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
//ÉÏ´«Îļþ¸öÈËÏûÏ¢
|
public bool LoadUpFile2(Int64 iFileID, string sPath, int sSize, string sFileName, string sUpMan, string ROperator, string LoadDate, int HBillStatus)
|
{
|
try
|
{
|
SqlConnection con = new SqlConnection(_sqlConnection);
|
con.Open();
|
byte[] FileList = this.FileToByteArray(sPath);
|
string commandText = @" INSERT INTO oa_PicBill (MainID,sPath,picsize,sFileName,pic,operator,ROperator,isread,Status,LoadDate) " +
|
"VALUES (" + iFileID.ToString() + ",'" + sPath + "'," + sSize.ToString() + ",'" +
|
sFileName + "',@FileList2,'" + sUpMan + "','" + ROperator + "',0,'','" + LoadDate + "','" + HBillStatus + "')";
|
SqlCommand comm = new SqlCommand(commandText, con);
|
comm.Parameters.AddWithValue("@FileList2", FileList);
|
comm.ExecuteNonQuery();
|
con.Close();
|
}
|
catch (Exception e)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
|
//ÉÏ´«Îļþ
|
public bool LoadUpFile(string sTable, string sFieldName, string sPath, long HInterID, Pub_Class.ClsSqlHelper oCn)
|
{
|
try
|
{
|
string s = "";
|
byte[] FileList = FileToByteArray(sPath);
|
string commandText = @" INSERT INTO " + sTable + "(HInterID," + sFieldName + ") " +
|
"VALUES (" + HInterID.ToString() + ",@FileList)";
|
if (!oCn.CreateCommand(commandText, FileList, ref s))
|
{
|
return false;
|
}
|
return true;
|
}
|
catch (Exception e)
|
{
|
return false;
|
}
|
}
|
|
//ÉÏ´«ÎļþA3
|
public bool LoadUpFile(string sTable, string sFieldName, string sPath, string HBillNo, string sType, Pub_Class.ClsSqlHelper oCn)
|
{
|
try
|
{
|
string s = "";
|
byte[] FileList = FileToByteArray(sPath);
|
string commandText = @" INSERT INTO " + sTable + "(HBillNo,HBillType," + sFieldName + ") " +
|
"VALUES ('" + HBillNo + "','" + sType + "',@FileList)";
|
if (!oCn.CreateCommand(commandText, FileList, ref s))
|
{
|
return false;
|
}
|
return true;
|
}
|
catch (Exception e)
|
{
|
return false;
|
}
|
}
|
|
//ÉÏ´«Îļþ¹ÜÀíÎļþ
|
public bool LoadUpFile3(Int64 FFileSize, string PicName, string PicType, string PicPath, string LoadDate, string Remark, int ParentID, string sLoadMan)
|
{
|
//PicPath Îļþ·¾¶ PicName ÎļþÃû³Æ LoadMan ÉÏ´«ÈË PicType ÎļþÀàÐÍ LoadDate ÉÏ´«Ê±¼ä
|
|
// YF_PictureID ID, PicType ÀàÐÍ,PicName ÎļþÃû³Æ, PicPath Îļþ·¾¶,LoadDate ÉÏ´«Ê±¼ä,LoadMan ÉÏ´«ÈË,CloseDate null
|
//, CloseMan null, Remark ÃèÊö,YF_CmpolderMainID 0
|
//,YF_CmpolderSubID 0, YF_CmpolderType '',ParentID Ê÷ÐÎID,BbNumber, FFile, BbID ,LJnull
|
|
//grdCSFJ.Columns[HFileNameCol].HeaderText = "ÎļþÃû³Æ";
|
//grdCSFJ.Columns[HFilePathCol].HeaderText = "Îļþ·¾¶";
|
//grdCSFJ.Columns[HUpManCol].HeaderText = "ÉÏ´«ÈË";
|
//grdCSFJ.Columns[HROperatorCol].HeaderText = "½ÓÊÕÈË";
|
//grdCSFJ.Columns[iFileIDCSCol].HeaderText = "ID";
|
|
|
//if (oFile2.WriteFile2("Pic"
|
// , DBUtility.ClsPub.AppPath + @"\a\" + DBUtility.ClsPub.isStrNull(grdJSFJ.Rows[grdJSFJ.CurrentRow.Index].Cells[HFileNameCol].Value)
|
// , DBUtility.ClsPub.isLong(grdJSFJ.Rows[grdJSFJ.CurrentRow.Index].Cells[iFileIDJSCol].Value), oCNK32) == false)
|
try
|
{
|
SqlConnection con = new SqlConnection(_sqlConnection);
|
con.Open();
|
byte[] FileList = this.FileToByteArray(PicPath);
|
string commandText = @" INSERT INTO oa_picturebill (FFileSize,PicName,PicType,PicPath,LoadDate,Remark,YF_CmpolderMainID,YF_CmpolderSubID,YF_CmpolderType,ParentID,BbNumber,FFile,BbID,LoadMan) " +
|
"VALUES (" + FFileSize.ToString() + ",'" + PicName + "','" + PicType + "','" + PicPath + "','" + LoadDate + "','" + Remark + "',0,0,''," + ParentID.ToString() + ",''" +
|
",@FileList,0,'" + sLoadMan + "')";
|
SqlCommand comm = new SqlCommand(commandText, con);
|
comm.Parameters.AddWithValue("@FileList", FileList);
|
comm.ExecuteNonQuery();
|
con.Close();
|
}
|
catch (Exception e)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
|
//°ÑÎļþת»»³Ébyte[]
|
public byte[] FileToByteArray(String FilePath)
|
{
|
FileStream stream = new FileInfo(FilePath).OpenRead();
|
byte[] buffer = new byte[stream.Length];
|
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
|
stream.Close();
|
stream = null;
|
return buffer;
|
return null;
|
}
|
|
//ÏÂÔØÎļþ²¢ÔËÐÐ
|
public bool WriteFile(string sFieldName, string sFileName, long HInterID, Pub_Class.ClsSqlHelper oCn)
|
{
|
string s = "";
|
SqlDataReader dr = oCn.RunReader("select FFile from OA_Accessories where FItemID=" + HInterID.ToString(), "OA_Accessories", ref s);
|
if (dr == null)
|
{
|
return false;
|
}
|
byte[] oFile = null;
|
if (dr.Read())
|
{
|
oFile = (byte[])dr[sFieldName];
|
}
|
FileStream fs;
|
FileInfo fi = new FileInfo(sFileName);
|
fs = fi.OpenWrite();
|
fs.Write(oFile, 0, oFile.Length);
|
fs.Close();
|
dr.Close();
|
return true;
|
}
|
|
//ÏÂÔØÎļþ²¢ÔËÐиöÈËÏûÏ¢
|
public bool WriteFile2(string sFieldName, string sFileName, long HInterID, Pub_Class.ClsSqlHelper oCn)
|
{
|
string s = "";
|
oCn.RunProc("Update oa_PicBill set " +
|
"HBillStatus= 1 Where ID =" + HInterID.ToString(), ref DBUtility.ClsPub.sExeReturnInfo);
|
SqlDataReader dr = oCn.RunReader("select Pic from oa_PicBill where ID=" + HInterID.ToString(), "oa_PicBill", ref s);
|
if (dr == null)
|
{
|
return false;
|
}
|
byte[] oFile = null;
|
if (dr.Read())
|
{
|
oFile = (byte[])dr[sFieldName];
|
}
|
FileStream fs;
|
FileInfo fi = new FileInfo(sFileName);
|
fs = fi.OpenWrite();
|
|
|
|
fs.Write(oFile, 0, oFile.Length);
|
fs.Close();
|
dr.Close();
|
|
return true;
|
}
|
//ÏÂÔØÎļþ
|
public bool WriteFile(string sSQL, string sFieldName, string sFileName, long HInterID, Pub_Class.ClsSqlHelper oCn)
|
{
|
string s = "";
|
SqlDataReader dr = oCn.RunReader("select HFile from Xt_Accessories where HInterID=" + HInterID.ToString(), "Xt_Accessories", ref s);
|
if (dr == null)
|
{
|
return false;
|
}
|
byte[] oFile = null;
|
if (dr.Read())
|
{
|
oFile = (byte[])dr[sFieldName];
|
}
|
FileStream fs;
|
FileInfo fi = new FileInfo(sFileName);
|
fs = fi.OpenWrite();
|
fs.Write(oFile, 0, oFile.Length);
|
fs.Close();
|
dr.Close();
|
return true;
|
}
|
|
//ÏÂÔØÎļþ²¢ÔËÐйÜÀíÎļþ
|
public bool WriteFile3(string sFieldName, string sFileName, long YF_PictureID, Pub_Class.ClsSqlHelper oCn)
|
{
|
string s = "";
|
SqlDataReader dr = oCn.RunReader("select FFile from oa_picturebill where YF_PictureID=" + YF_PictureID.ToString(), "oa_picturebill", ref s);
|
if (dr == null)
|
{
|
return false;
|
}
|
byte[] oFile = null;
|
if (dr.Read())
|
{
|
oFile = (byte[])dr[sFieldName];
|
}
|
FileStream fs;
|
FileInfo fi = new FileInfo(sFileName);
|
fs = fi.OpenWrite();
|
fs.Write(oFile, 0, oFile.Length);
|
fs.Close();
|
dr.Close();
|
return true;
|
}
|
|
//ÏÂÔØÎļþA3
|
public bool WriteFile(string sSQL, string sFieldName, string sFileName, string HBillNo, string sType, Pub_Class.ClsSqlHelper oCn)
|
{
|
string s = "";
|
SqlDataReader dr = oCn.RunReader("select HFile from Xt_Accessories where HBillNo='" + HBillNo + "' and HBillType='" + sType + "' order by HItemID desc", "Xt_Accessories", ref s);
|
if (dr == null)
|
{
|
return false;
|
}
|
byte[] oFile = null;
|
if (dr.Read())
|
{
|
oFile = (byte[])dr[sFieldName];
|
}
|
FileStream fs;
|
FileInfo fi = new FileInfo(sFileName);
|
fs = fi.OpenWrite();
|
fs.Write(oFile, 0, oFile.Length);
|
fs.Close();
|
dr.Close();
|
return true;
|
}
|
|
//´ò¿ªÎļþ
|
//ɾ³ýµ¥¾Ý
|
public bool DeleteFile(Int64 lngBillKey, ref string sReturn, Pub_Class.ClsSqlHelper oCn)
|
{
|
try
|
{
|
oCn.BeginTran();
|
//ɾ³ýÃ÷ϸ±í
|
oCn.RunProc("Delete From OA_Accessories where FItemID=" + lngBillKey.ToString());
|
sReturn = "ɾ³ý¸½¼þ³É¹¦£¡";
|
oCn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
return false;
|
}
|
}
|
|
|
//ɾ³ýµ¥¾Ý¹ÜÀíÎļþ
|
public bool DeleteFile3(Int64 lngBillKey, ref string sReturn, Pub_Class.ClsSqlHelper oCn)
|
{
|
try
|
{
|
|
oCn.BeginTran();
|
//ɾ³ýÃ÷ϸ±í
|
oCn.RunProc("Delete From oa_picturebill where YF_PictureID=" + lngBillKey.ToString());
|
sReturn = "ɾ³ý¸½¼þ³É¹¦£¡";
|
oCn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
return false;
|
}
|
}
|
|
|
//ɾ³ýµ¥¾Ý
|
public bool DeleteBill(Int64 lngBillKey, ref string sReturn, Pub_Class.ClsSqlHelper oCn)
|
{
|
try
|
{
|
oCn.BeginTran();
|
//ɾ³ýÃ÷ϸ±í
|
oCn.RunProc("Delete From Xt_Accessories where HInterID=" + lngBillKey.ToString());
|
//ɾ³ýÖ÷±í
|
oCn.RunProc("Delete From Xt_FileList where HInterID=" + lngBillKey.ToString());
|
sReturn = "ɾ³ý¸½¼þ³É¹¦£¡";
|
oCn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
return false;
|
}
|
}
|
//ÐÂÔöµ¥¾Ý
|
public bool AddBill(ref string sReturn, Pub_Class.ClsSqlHelper oCn)
|
{
|
try
|
{
|
//µÃµ½mainid
|
this.HInterID = DBUtility.ClsPub.CreateBillID(MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo);
|
//ÈôMAINDIÖØ¸´ÔòÖØÐ»ñÈ¡
|
oCn.BeginTran();
|
//Ö÷±í
|
oCn.RunProc("Insert Into Xt_FileList " +
|
"(HInterID,HFileSize,HFileType" +
|
",HPath,HFileName,HMaker,HMakeDate" +
|
",HRemark,HBillNo,HBillType" +
|
") " +
|
" values(" + this.HInterID.ToString() + "," + this.HFileSize.ToString() + ",'" + this.HFileType + "'" +
|
",'" + this.HPath + "','" + this.HFileName + "','" + DBUtility.ClsPub.CurUserName + "','" + DBUtility.ClsPub.GetServerDate(-1) + "'" +
|
",'" + this.HRemark + "','" + this.HBillNo + "','" + this.HBillType + "'" +
|
") ");
|
sReturn = "±£´æ¸½¼þ³É¹¦£¡";
|
oCn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
return false;
|
}
|
}
|
|
//ÏÔʾµ¥¾Ý
|
public bool ShowBill(Int64 lngBillKey, ref string sReturn, Pub_Class.ClsSqlHelper oCn)
|
{
|
try
|
{
|
//²éѯÖ÷±í
|
DataSet Ds;
|
Ds = oCn.RunProcReturn("Select * from Xt_FileList Where HInterID=" + lngBillKey.ToString(), "Xt_FileList");
|
if (Ds.Tables[0].Rows.Count == 0)
|
{
|
sReturn = "¸½¼þδÕÒµ½£¡";
|
return false;
|
}
|
//¸³Öµ
|
this.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
|
this.HFileName = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HFileName"].ToString());
|
//
|
sReturn = "ÏÔʾ¸½¼þ³É¹¦£¡";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
return false;
|
}
|
}
|
|
//ÏÔʾµ¥¾ÝA3
|
public bool ShowBill(string lngBillKey, string sType, ref string sReturn, Pub_Class.ClsSqlHelper oCn)
|
{
|
try
|
{
|
//²éѯÖ÷±í
|
DataSet Ds;
|
Ds = oCn.RunProcReturn("Select top 1 * from Xt_FileList Where HBillNo='" + lngBillKey + "' and HBillType='" + sType + "' order by HItemID desc", "Xt_FileList");
|
if (Ds.Tables[0].Rows.Count == 0)
|
{
|
sReturn = "¸½¼þδÕÒµ½£¡";
|
return false;
|
}
|
//¸³Öµ
|
this.HBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillNo"].ToString());
|
this.HFileName = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HFileName"].ToString());
|
//
|
sReturn = "ÏÔʾ¸½¼þ³É¹¦£¡";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
return false;
|
}
|
}
|
|
}
|
}
|