using System; 
 | 
using System.Collections.Generic; 
 | 
using System.ComponentModel; 
 | 
using System.Data; 
 | 
using System.Drawing; 
 | 
using System.Text; 
 | 
using System.Windows.Forms; 
 | 
using System.IO; 
 | 
using System.Diagnostics; 
 | 
using DBUtility; 
 | 
using Pub_Class; 
 | 
  
 | 
namespace BLL 
 | 
{ 
 | 
    public partial class Xt_File : Form 
 | 
    { 
 | 
        public string sServer = ""; 
 | 
        public string sDataBase = ""; 
 | 
        public string sUser = ""; 
 | 
        public string sPassword = ""; 
 | 
        public Xt_File() 
 | 
        { 
 | 
            InitializeComponent(); 
 | 
            //sServer = ClsIni.ReadIni("Erp", "Server", DBUtility.ClsPub.AppPath + @"\" + "HXErp.ini"); 
 | 
            //sDataBase = ClsIni.ReadIni("Erp", "DataBase", DBUtility.ClsPub.AppPath + @"\" + "HXErp.ini"); 
 | 
            //sUser = ClsIni.ReadIni("Erp", "UserName", DBUtility.ClsPub.AppPath + @"\" + "HXErp.ini"); 
 | 
            //sPassword = ClsIni.ReadIni("Erp", "PassWord", DBUtility.ClsPub.AppPath + @"\" + "HXErp.ini"); 
 | 
  
 | 
            //oFile = new ClsFile(sServer, sDataBase, sUser, sPassword); 
 | 
        } 
 | 
        public DBUtility.frmBillQueryCondition_New frmCondition; 
 | 
        const string ViewName = "h_v_Xt_FileList"; 
 | 
        const string ModCaption = "单据附件列表";  
 | 
        ClsXt_FileCtrl oBill = new ClsXt_FileCtrl(); 
 | 
        // 
 | 
        public long HBillID; 
 | 
        public string HBillNo; 
 | 
        public string HBillType; 
 | 
        // 
 | 
        public ClsXt_FileCtrl oFrm; 
 | 
        // 
 | 
        private void initGrid() 
 | 
        { 
 | 
            DBUtility.Xt_BaseBillFun.initGridList(grdMain, this.Name); 
 | 
        } 
 | 
  
 | 
        private void Display() 
 | 
        { 
 | 
            SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN(); 
 | 
            DataSet DSet; 
 | 
            string sSql = ""; 
 | 
            string sWhere = "and HBillNo='" + this.HBillNo + "' and HBillType='" +this.HBillType+ "'"; 
 | 
            //过滤条件 
 | 
            sSql = "select * from h_v_Xt_FileList where 1=1 " + sWhere + " order by HMainID "; 
 | 
            // 
 | 
            DSet = SubCn.RunProcReturn(sSql, "h_v_Xt_FileList", ref DBUtility.ClsPub.sExeReturnInfo); 
 | 
            //生成首行标题 
 | 
            if (DSet == null) 
 | 
            { 
 | 
                MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo); 
 | 
                return; 
 | 
            } 
 | 
            // 
 | 
            for (int i = 0; i < grdMain.ColumnCount; i++) 
 | 
            { 
 | 
                grdMain.Columns[i].Frozen = false; 
 | 
            } 
 | 
            // 
 | 
            grdMain.DataSource = DSet.Tables[0].DefaultView; 
 | 
  
 | 
            //冻结 
 | 
            int FrCol = DBUtility.ClsPub.isInt(frmCondition.txtFrozenCol.Text); 
 | 
            string s = frmCondition.cmbHComplete.Text; 
 | 
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s, FrCol); 
 | 
            //画线 
 | 
            GraphLine(); 
 | 
        } 
 | 
  
 | 
        private void timer1_Tick(object sender, EventArgs e) 
 | 
        { 
 | 
            timer1.Enabled = false;  
 | 
            Display(); 
 | 
        } 
 | 
  
 | 
        private void tc_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            this.Close(); 
 | 
        } 
 | 
  
 | 
        private void sx_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            timer1.Enabled = true; 
 | 
        } 
 | 
  
 | 
        private void ck_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            Sub_ShowBill(); 
 | 
        } 
 | 
  
 | 
        private void Sub_ShowBill() 
 | 
        { 
 | 
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); 
 | 
            Int64 lngBillKey = 0; 
 | 
            if (grdMain.CurrentRow == null) 
 | 
                return; 
 | 
            lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value); 
 | 
            if (lngBillKey == 0) 
 | 
                return; 
 | 
            ClsXt_FileCtrl oBill = new ClsXt_FileCtrl(); 
 | 
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo, oCn)) 
 | 
            { 
 | 
                if (oBill.CompressBackFile(DBUtility.ClsPub.AppPath + @"\a\" + oBill.HFileName, oBill.HInterID, oCn)) 
 | 
                { 
 | 
                    ShowFile(oBill.HFileName); 
 | 
                } 
 | 
            } 
 | 
            else  
 | 
            { 
 | 
                MessageBox.Show("附件未找到!", "提示"); 
 | 
            } 
 | 
            oBill = null; 
 | 
        } 
 | 
  
 | 
        private void ShowFile(string FileName) 
 | 
        { 
 | 
            string sHPath = ""; 
 | 
            sHPath = DBUtility.ClsPub.AppPath + @"\a\" + FileName; 
 | 
            Process p = new Process(); 
 | 
            p.StartInfo.FileName = sHPath; 
 | 
            p.Start(); 
 | 
            p.WaitForExit(); 
 | 
            File.Delete(sHPath); 
 | 
        } 
 | 
        private Int32 Fun_GetCol(string sCol) 
 | 
        { 
 | 
            for (int c = 0; c < grdMain.ColumnCount; c++) 
 | 
            { 
 | 
                if (DBUtility.ClsPub.isStrNull(grdMain.Columns[c].HeaderText).ToUpper().Trim() == sCol.Trim().ToUpper()) 
 | 
                { 
 | 
                    return c; 
 | 
                } 
 | 
            } 
 | 
            return 0; 
 | 
        } 
 | 
  
 | 
        private void Xt_File_Load(object sender, EventArgs e) 
 | 
        { 
 | 
            // 
 | 
            frmCondition = new frmBillQueryCondition_New(); 
 | 
            this.Text = ModCaption; 
 | 
            lblCaption.Text = ModCaption; 
 | 
            initGrid(); 
 | 
        } 
 | 
  
 | 
        private void cx_Click(object sender, EventArgs e) 
 | 
        { 
 | 
              
 | 
        } 
 | 
  
 | 
        private void sc_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            Sub_DeleteBill(); 
 | 
        } 
 | 
        //删除 
 | 
        private void Sub_DeleteBill() 
 | 
        { 
 | 
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); 
 | 
            Int64 lngBillKey = 0; 
 | 
            if (grdMain.CurrentRow == null) 
 | 
                return; 
 | 
            lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("HMainID")].Value); 
 | 
            if (lngBillKey == 0) 
 | 
                return; 
 | 
            ClsXt_FileCtrl oBill = new ClsXt_FileCtrl(); 
 | 
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo, oCn)) 
 | 
            { 
 | 
                if (MessageBox.Show("确定要删除当前附件?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) 
 | 
                { 
 | 
                    //if (oBill.HChecker != "") 
 | 
                    //{ 
 | 
                    //    MessageBox.Show("单据已经审核,不能删除!", "提示"); 
 | 
                    //    return; 
 | 
                    //} 
 | 
                    if (!oBill.DeleteBill(oBill.HInterID, ref DBUtility.ClsPub.sExeReturnInfo, oCn)) 
 | 
                    { 
 | 
                        MessageBox.Show(DBUtility.ClsPub.sExeReturnInfo, "提示"); 
 | 
                        return; 
 | 
                    } 
 | 
                    else 
 | 
                    { 
 | 
                        Display(); 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                MessageBox.Show("附件未找到", "提示"); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        private void timer2_Tick(object sender, EventArgs e) 
 | 
        { 
 | 
              
 | 
  
 | 
        } 
 | 
  
 | 
        private void yl_Click(object sender, EventArgs e) 
 | 
        { 
 | 
  
 | 
        } 
 | 
  
 | 
        private void bclk_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            //保存列宽 
 | 
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); 
 | 
        } 
 | 
  
 | 
        private void mrlk_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name); 
 | 
        } 
 | 
        //划线 
 | 
        private void GraphLine() 
 | 
        { 
 | 
             
 | 
        } 
 | 
  
 | 
        //设置网格 
 | 
        private void SetDataGrid(int BRow, int BCol, int ERow, int ECol, string sText) 
 | 
        { 
 | 
            for (int i = BRow; i <= ERow; i++) 
 | 
            { 
 | 
                for (int j = BCol; j <= ECol; j++) 
 | 
                { 
 | 
                    grdMain.Rows[i].Cells[j].Value = DBNull.Value; 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
  
 | 
        private void GraphicsGrid() 
 | 
        { 
 | 
              
 | 
        } 
 | 
  
 | 
        private void grdMain_DoubleClick(object sender, EventArgs e) 
 | 
        { 
 | 
            Sub_ShowBill(); 
 | 
        } 
 | 
  
 | 
        private void grdMain_Paint(object sender, PaintEventArgs e) 
 | 
        { 
 | 
            GraphicsGrid(); 
 | 
        } 
 | 
  
 | 
        //上传附件 
 | 
        private void Loading_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            OpenFileDialog oDlg = new OpenFileDialog(); 
 | 
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); 
 | 
            oBill = new ClsXt_FileCtrl(); 
 | 
            oDlg.Filter = "所有文件|*.*"; 
 | 
            if (oDlg.ShowDialog() == DialogResult.OK) 
 | 
            { 
 | 
                if (oDlg.FileName != "") 
 | 
                { 
 | 
                    FileInfo fi = new FileInfo(oDlg.FileName); 
 | 
                    oBill.HFileSize = fi.Length; 
 | 
                    oBill.HFileType = fi.Extension; 
 | 
                    oBill.HPath = fi.FullName; 
 | 
                    oBill.HFileName = fi.Name; 
 | 
                    oBill.HRemark = ""; 
 | 
                    oBill.HBillID = this.HBillID; 
 | 
                    oBill.HBillNo = this.HBillNo; 
 | 
                    oBill.HBillType = this.HBillType; 
 | 
                    if (oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo, oCn)) 
 | 
                    { 
 | 
                        //压缩附件并保存 
 | 
                        if (oBill.CompressFile(oDlg.FileName, "Xt_Accessories", "HFile", oBill.HInterID, oCn)) 
 | 
                        { 
 | 
                            Display(); 
 | 
                        } 
 | 
                    } 
 | 
                    else 
 | 
                    { 
 | 
                        MessageBox.Show("上传失败!原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示"); 
 | 
                        return; 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
  
 | 
        //下载附件 
 | 
        private void xz_Click(object sender, EventArgs e) 
 | 
        { 
 | 
            Sub_DownLoad(); 
 | 
        } 
 | 
  
 | 
  
 | 
        private void Sub_DownLoad() 
 | 
        { 
 | 
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); 
 | 
            Int64 lngBillKey = 0; 
 | 
            string FileName = ""; 
 | 
            string HouZhui = ""; 
 | 
            int i = 0; 
 | 
            SaveFileDialog oDlg = new SaveFileDialog(); 
 | 
            if (grdMain.CurrentRow == null) 
 | 
                return; 
 | 
            lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value); 
 | 
            if (lngBillKey == 0) 
 | 
                return; 
 | 
            ClsXt_FileCtrl oBill = new ClsXt_FileCtrl(); 
 | 
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo, oCn)) 
 | 
            { 
 | 
                FileName = oBill.HFileName; 
 | 
                i = FileName.LastIndexOf("."); 
 | 
                HouZhui = "." + FileName.Substring(i + 1, FileName.Length - i - 1); 
 | 
                HouZhui = HouZhui + "|" + HouZhui; 
 | 
                oDlg.FileName = FileName; 
 | 
                oDlg.Filter = HouZhui + "|所有文件|*.*"; 
 | 
                if (oDlg.ShowDialog() == DialogResult.OK) 
 | 
                { 
 | 
                    if (oDlg.FileName != "") 
 | 
                    { 
 | 
                        if (oBill.CompressBackFile(DBUtility.ClsPub.AppPath + @"\a\" + FileName, oBill.HInterID, oCn)) 
 | 
                        { 
 | 
                            File.Move(DBUtility.ClsPub.AppPath + @"\a\" + FileName, oDlg.FileName); 
 | 
                            // 
 | 
                            MessageBox.Show("附件下载成功!", "提示"); 
 | 
                            return; 
 | 
                        } 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                MessageBox.Show("附件未找到!", "提示"); 
 | 
            } 
 | 
            oBill = null; 
 | 
  
 | 
  
 | 
        } 
 | 
  
 | 
  
 | 
  
 | 
    } 
 | 
} 
 |