yusijie
2024-04-10 99136e90515aae6031bf6ba870835774735172b4
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace OAM
{
    public partial class frmWorkBillView : Form
    {
        public frmWorkBillView()
        {
            InitializeComponent();
        }
 
        public const int HFileNameCol = 0;//huan
        public const int HFilePathCol = 1;
        public const int HUpManCol = 2;
        public const int HItemIDCol = 3;
        //
        public const int MainType = 2;
        public long ID;
 
        private void cmdHasten_Click(object sender, EventArgs e)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            if (MessageBox.Show("确认要催促对方?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }
            lblHasten.Text = DBUtility.ClsPub.isStrNull(DBUtility.ClsPub.isInt(lblHasten.Text) + 1);
            oCn.RunProc("update oa_workbillmain set Hasten=Hasten+1,isback=0,isread=0 where id=" + ID);
            oCn.RunProc("update oa_workbillsub2 set isread=0 where mainid=" + ID);
        }
 
        private void cmdSelectEmps2_Click(object sender, EventArgs e)
        {
            DBUtility.Gy_UserSelect oUser = new DBUtility.Gy_UserSelect();
            oUser.bSingle = false;
            oUser.ShowDialog();
            if (oUser.IsOk == 1)
            {
                txtRtransmitMan.Text = oUser.sReturn;
            }
            else
            {
                txtRtransmitMan.Text = "";
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
 
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            if (txtRtransmitMan.Text.Trim() == "")
            {
                MessageBox.Show("请选择转发人");
            }
            oCn.RunProc("update oa_workbillmain set RtransmitMan='" + txtRtransmitMan.Text.ToString() + "',transmitMan='" + DBUtility.ClsPub.CurUserName + "' where id=" + ID);
            DataSet Ds;
            long i = 0;
            Ds = oCn.RunProcReturn("select max(subid) as  MaxID from oa_workbillsub2 where mainid=" + ID, "oa_workbillsub2");
            if (Ds != null && Ds.Tables[0].Rows.Count != 0)
            {
                i = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
            }
            if (txtRtransmitMan.Text != "")
            {
                string[] s = txtRtransmitMan.Text.Split(',');
                int len = s.Length;
                for (int z = 0; z < len; z++)
                {
                    i = i + 1;
                    string k = s[z].ToString();
                    oCn.RunProc("insert into oa_workbillsub2 (MainID,SubID,ROperator,isRead,isKnow) " +
                                "values (" +
                                ID + "," + i + ",'" + k + "',0,0)");
                }
            }
            MessageBox.Show("已经成功转发!");
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            if (txtOperator.Text == DBUtility.ClsPub.CurUserName)
            {
                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_workbillsub where Mainid=" + ID);
                    oCn.RunProc("delete from oa_workbillsub2 where Mainid=" + ID);
                    oCn.RunProc("delete from oa_workbillMain where id=" + ID);
                    MessageBox.Show("删除成功!");
                    this.Close();
                }
                else
                {
                }
            }
            else
            {
 
                MessageBox.Show("对不起!只有发送人才能删除!");
            }
 
           
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
           SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
           if (txtROperator.Text == DBUtility.ClsPub.CurUserName)
           {
               if (txtContext_New.Text == "")
               {
                   MessageBox.Show("请填写内容!");
                   return;
               }
               string Context_New = txtContext_New.Text.Replace("'", "‘");
               int Rows = grdMain.Rows.Count + 1;
               oCn.RunProc("Insert into oa_workbillsub(mainid,id,context,operator,opdate,sisEnd) values(" + ID + "," + Rows + ",'" + Context_New + "','" + DBUtility.ClsPub.CurUserName + "',getdate(),1)");
               oCn.RunProc("update oa_workbillmain set isend=1 where id=" + ID + " and roperator='" + DBUtility.ClsPub.CurUserName + "'");
               oCn.RunProc("insert into oa_workbillsub2(mainid,subid,roperator,isread,isknow) values(" + ID + "," + GetMaxSubID(ID) + ",'" + txtOperator.Text.ToString() + "',0,0)");
               Display();
           }
           else
           {
               MessageBox.Show("对不起,你不能结案!");
           }
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            if (txtOperator.Text == DBUtility.ClsPub.CurUserName)
            {
                frmWorkBillView_Dlg oDlg = new frmWorkBillView_Dlg();
                oDlg.ShowDialog();
                if (oDlg.isOK == 1)
                {
                    string Context_New = oDlg.txtHContext.Text.Replace("'", "‘");
                    int Rows = grdMain.Rows.Count + 1;
                    oCn.RunProc("Insert into oa_workbillsub(mainid,id,context,operator,opdate,sislast) values(" + ID + "," + Rows + ",'" + Context_New + "','" + DBUtility.ClsPub.CurUserName + "',getdate(),1)");
                    oCn.RunProc("update oa_workbillmain set islast=1 , HEvaluateStatusID=" + oDlg.txtHEvaluateStatusID.SelectedIndex + " where id=" + ID);
                    oCn.RunProc("insert into oa_workbillsub2(mainid,subid,roperator,isread,isknow) values(" + ID + "," + GetMaxSubID(ID) + ",'" + txtROperator.Text + "',0,0)");
                    Display();
                }
            }
            else
            {
                MessageBox.Show("对不起,你不能验证");
            }
        }
 
        private void cmdSend_Click(object sender, EventArgs e)
        {
            DBUtility.ClsPub.SaveGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);
            DBUtility.ClsPub.SaveGridView(grdFJ, this.Name + "grdFJ", DBUtility.ClsPub.AppPath); 
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            if (txtContext_New.Text == "")
            {
                MessageBox.Show("请填写回复内容!");
                return;
            }
            int Rows = grdMain.Rows.Count + 1;
            oCn.RunProc("Insert into oa_workbillsub(mainid,id,context,operator,opdate) values(" + ID + "," + Rows + ",'" + txtContext_New.Text.ToString() + "','" + DBUtility.ClsPub.CurUserName + "',getdate())");
            oCn.RunProc("update oa_workbillmain set isback=1 where id=" + ID + " and roperator='" + DBUtility.ClsPub.CurUserName + "'");
            oCn.RunProc("insert into oa_workbillsub2(mainid,subid,roperator,isread,isknow) values(" + ID + "," + GetMaxSubID(ID) + ",'" + txtOperator.Text.ToString() + "',0,0)");
            Display();
        }
 
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            DBUtility.ClsPub.SaveGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);
            DBUtility.ClsPub.SaveGridView(grdFJ, this.Name + "grdFJ", DBUtility.ClsPub.AppPath); 
            this.Close();
        }
 
        public void Display()
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            DataSet Ds;
            Ds = oCn.RunProcReturn("Select * from oa_workbillmain where id=" + ID, "oa_workbillmain", ref DBUtility.ClsPub.sExeReturnInfo);
            if (Ds == null )
            {
                MessageBox.Show("显示失败!原因:" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            txtContext.Text = Ds.Tables[0].Rows[0]["context"].ToString();
            txtDesc.Text = Ds.Tables[0].Rows[0]["Description"].ToString();
            if (Ds.Tables[0].Rows[0]["roperator"].ToString() == DBUtility.ClsPub.CurUserName)
            {
                oCn.RunProc("update oa_workbillmain set isread=1 where id=" + ID);
            }
            //   If Trim(oRs!operator & "") = Trim(CurUserName) Then
            //            Toolbar1.Buttons("cchu").Enabled = True
            //            Toolbar1.Buttons("yzh").Enabled = True
            //        Else
            //            Toolbar1.Buttons("cchu").Enabled = False
            //            Toolbar1.Buttons("yzh").Enabled = False
            //        End If
            //        If Trim(oRs!roperator & "") = Trim(CurUserName) Then
            //                Toolbar1.Buttons("ja").Enabled = True
            //        Else
            //            Toolbar1.Buttons("ja").Enabled = False
            //        End If
            //
            lblHasten.Text = Ds.Tables[0].Rows[0]["hasten"].ToString();
            txtOperator.Text = Ds.Tables[0].Rows[0]["operator"].ToString();
            txtROperator.Text = Ds.Tables[0].Rows[0]["roperator"].ToString();
            txtRoperator2.Text = Ds.Tables[0].Rows[0]["roperator2"].ToString();
            txtRtransmitMan.Text = Ds.Tables[0].Rows[0]["rtransmitman"].ToString();
            txttransmitMan.Text = Ds.Tables[0].Rows[0]["transmitman"].ToString();
            txtHRemark.Text = Ds.Tables[0].Rows[0]["HRemark"].ToString();
            txtHBillNo.Text = Ds.Tables[0].Rows[0]["hbillno"].ToString();
            cmbHLevel.Text = Ds.Tables[0].Rows[0]["HLevel"].ToString();
            //
            //If (Eva.GetInfoByID(Val(oRs!HEvaluateStatusID))) Then
            //    cmbHEvaluateStatus.Text = Trim(Eva.HName & "")
            //Else
            //    cmbHEvaluateStatus.Text = ""
            //End If
            // 
            cmbHEvaluateStatus.SelectedIndex =DBUtility.ClsPub.isInt( Ds.Tables[0].Rows[0]["HEvaluateStatusID"].ToString());
            if (Ds.Tables[0].Rows[0]["FDate"].ToString() != "")
            {
                dtpFDate.Value = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FDate"].ToString());
            }
            if (Ds.Tables[0].Rows[0]["HCommDate"].ToString() != "")
            {
                DtpHCommDate.Value = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HCommDate"].ToString());
            }
 
            oCn.RunProc("update oa_workbillsub2 set isread=1 where mainid=" + ID + " and roperator='" + DBUtility.ClsPub.CurUserName + "'");
 
            Ds = oCn.RunProcReturn("Select Operator 发送人,convert(varchar(5),opdate,110)+' '+convert(varchar(5),opdate,108) 发送日期,case when isnull(sisend,0)<>0 then '结案:'+Context else  case when isnull(sislast,0)<>0 then '验证:'+Context else '回复:'+Context end end 内容 from oa_workbillsub  where mainid=" + ID + " and id>=0 order by opdate desc", "oa_workbillsub", ref DBUtility.ClsPub.sExeReturnInfo);
            if (Ds == null)
            {
                MessageBox.Show("显示失败!原因:" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            grdMain.DataSource = Ds.Tables[0].DefaultView;
            //附件   huan
            DisplayFJ();
            //
            DBUtility.ClsPub.GetGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);
        }
 
        private void frmWorkBillView_Load(object sender, EventArgs e)//huan
        {
            initGridFJ();
        }
 
        private void initGridFJ()//huanxin
        {
            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 void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            timer1.Interval = 60000;
            Display();
        }
 
        private void fsh_Click(object sender, EventArgs e)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            oCn.RunProc("");
        }
 
        private long GetMaxSubID(long MainID)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            DataSet Ds;
            long MaxSubID;
            Ds = oCn.RunProcReturn("select max(subid)as subid from  oa_workbillsub2 where mainid=" + MainID, "oa_workbillsub2");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                MaxSubID = 0;
            }
            else
            {
                MaxSubID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]) + 1;
            }
            return MaxSubID;
        }
 
        private void cmdAdd_Click(object sender, EventArgs e)//huan
        {
            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, MainType, 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 grdFJ_DoubleClick(object sender, EventArgs e)//huan
        {
            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));
        
        }
 
        private void cmdDel_Click(object sender, EventArgs e) //huan
        {
            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 splitContainer4_SplitterMoved(object sender, SplitterEventArgs e)
        {
 
        }
 
        private void grdMain_DoubleClick(object sender, EventArgs e)
        {
            frmUserset ofrmUserset = new frmUserset();
            string sName = "";
            if (grdMain.CurrentRow == null)
                return;
            sName = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("发送人")].Value);
            if (sName == "")
                return;
            ofrmUserset.UserName = sName;
            ofrmUserset.cmdOK.Enabled = false;
            timer1.Enabled = false;
            ofrmUserset.ShowDialog();
            timer1.Enabled = true;
        }
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
        }
 
        private void grdMain_Scroll(object sender, ScrollEventArgs e)
        {
            grdMain.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True;
        }
    }
}