yangle
2023-03-03 c2a9a460e38c7c196fe98a94e29e6330eac3626f
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
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 frmGGView3 : Form
    {
        public frmGGView3()
        {
            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;
 
        private void cmdSend_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_gg3sub where Mainid=" + ID);
                oCn.RunProc("delete from oa_gg3 where id=" + ID);
                MessageBox.Show("删除成功!");
                this.Close();
            }
            else
            {
            }
          
        }
 
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void cmdCancel_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }
 
        public void Display()
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            DataSet Ds;
            DataSet Ds2;
            Ds = oCn.RunProcReturn("Select * from oa_gg3 where id=" + ID, "oa_gg3", 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_gg3sub set isread=1 where mainid=" + MainID + " and roperator='" + DBUtility.ClsPub.CurUserName + "'");
                Ds2 = oCn.RunProcReturn("select * from oa_ReadNum where sbill='oa_gg3' 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_gg3','" + DBUtility.ClsPub.CurUserName + "') ");
                }
            }
            //lblNum.Text = GetReadNum(MainID, "oa_gg3").ToString();
            txtEmp.Text = GetReadEmp(MainID, "oa_gg3");
            //附件   huan
            DisplayFJ();
            //DBUtility.ClsPub.GetGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);
            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_gg3 set z=''" +
                                            ",h2=''" +
                                            ",h=''" +
                                            ",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 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 frmGGView3_Load(object sender, EventArgs e)
        {
 
            initGridFJ();
            //this.Text = ModCaption;     //命名窗体标题
            //this.lblCaption.Text = ModCaption;//命名单据标题
        }
        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 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));
        
        }
    }
}