1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
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;
 
 
        }
 
 
 
    }
}