雅琪诺MES智能条码管理系统
jhz
2022-06-30 0d3b2bd4edaa7385e4ff96370c877be237af054b
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using gregn6Lib;
using Pub_Class;
 
namespace SCM
{
    public partial class Sc_PackUnionBillList : Form
    {
        public Sc_PackUnionBillList()
        {
            InitializeComponent();
        }
        public string ViewName = "h_v_ProductionLinePackagingList";
        public string ModCaption = "生产包装单列表";
        public const string ModRightName = "Sc_PackUnionBillList";
        public string HSourceBillType = "";
        SCM.WMSWeb.WebService1 oWeb = new SCM.WMSWeb.WebService1();
 
        private void initGrid()
        {
            ClsPub1.initGridList(grdMain, this.Name);
            grdMain.RowTemplate.Height = 60;//行高
            grdMain.ColumnHeadersHeight = 60;//设置表头行高
            grdMain.RowHeadersWidth = 260;
            grdMain.RowsDefaultCellStyle.Font = new Font("宋体", 22);
            grdMain.ReadOnly = true;
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            initGrid();
            dtpHBDate.Value = DBUtility.ClsPub.isDate(DateTime.Now.Date.ToShortDateString());
            dtpHEDate.Value = DBUtility.ClsPub.isDate(DateTime.Now.AddDays(1).ToShortDateString());
            Display();
        }
 
        private void Sc_PackUnionBillList_Load(object sender, EventArgs e)
        {
            //设置动态URL
            oWeb.Url = SCM.ClsPub1.WEBSURL;
            //
            //frmCondition = new frmBillQueryCondition_Base();
            this.Text = ModCaption;
            //lblCaption.Text = ModCaption;
            //oSumGrid.ogrdMain = grdMain;  //初始化 new
            //oSumGrid.oGridsum = grdSum;
            initGrid();
 
            dtpHBDate.Value = DBUtility.ClsPub.isDate(DateTime.Now.Date.ToShortDateString());
            dtpHEDate.Value = DBUtility.ClsPub.isDate(DateTime.Now.AddDays(1).ToShortDateString());
        }
 
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            timer2.Enabled = false;
            //cmbHSourceBillType.Text = HSourceBillType;
            //txtHSourceBillNo.Focus();
            //txtHSourceBillNo.SelectAll();
        }
 
        private void grdMain_Paint(object sender, PaintEventArgs e)
        {
            GraphicsGrid();
        }
 
        private void GraphicsGrid()
        {
            //画底线
            DBUtility.Xt_BaseBillFun.GraphicsGrid(grdMain);
            //画横线
            //DBUtility.Xt_BaseBillFun.GraphicsRowGrid(grdMain, iTopRow, iTopRow + 50, Fun_GetCol("hmainid"));
        }
 
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
        }
 
        //保存列宽
        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 Display()
        {
            string sql = " where 1 = 1 ";
            if (txtHSourceBillNo.Text.Trim() != "")
            {
                sql += " and 生产订单号 like '%" + txtHSourceBillNo.Text.Trim() + "%'";
            }
            if (txtHBarCode.Text.Trim() != "")
            {
                sql += " and 条码编号 like '%" + txtHBarCode.Text.Trim() + "%'";
            }
            sql += " and 制单日期 >= '" + dtpHBDate.Text.Trim() + "'";
            sql += " and 制单日期 <= '" + dtpHEDate.Text.Trim() + "'";
            //得到信息
            string sql2 = "select * from " + ViewName + sql;/*+" order by 唯一条码 desc";*/
            DataSet DS = oWeb.getDataSetBySQL(sql2, ViewName, ref DBUtility.ClsPub.sExeReturnInfo);
            if (DS==null ||  DS.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("没有找到相关源单信息!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            grdMain.DataSource = DS.Tables[0].DefaultView;
 
            
            DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name);
            int FrCol =0;
            string s = "是";
            ClsPub1.DisplayGrid(grdMain, this.Name, s, FrCol);
        }
 
 
 
 
 
        //双击列表
        private void grdMain_DoubleClick(object sender, EventArgs e)
        {
 
        }
 
 
        private void txtHSourceBillNo_TextChanged(object sender, EventArgs e)
        {
 
        }
 
        private void Tool_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
 
        }
 
        private void btnOK_Click(object sender, EventArgs e)
        {
            Display();
        }
 
        private void btnTC_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void cmbHSourceBillType_SelectedIndexChanged(object sender, EventArgs e)
        {
 
        }
 
        //删除按钮
        private void button1_Click(object sender, EventArgs e)
        {
            Sub_DeleteBill();
        }
 
        //删除
        private void Sub_DeleteBill()
        {
 
            try
            {
                if (AllowRow())
                {
                    if (MessageBox.Show("确定要删除当前项目?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        //得到HInterID
                        long sHInterID;
                        sHInterID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("HInterID")].Value);
                        oWeb.getRunProc("Delete from Sc_PackUnionBillSub where HInterID=" + sHInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                        oWeb.getRunProc("Delete from Sc_PackUnionBillMain where HInterID=" + sHInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                        oWeb.getRunProc("insert into System_log values(GETDATE(),'" + DBUtility.ClsPub.CurUserName + "','" + DBUtility.ClsPub.CurUserName + "','删除单据:" + DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("生产订单号")].Value) + "' ,'生产包装单列表','','删除')", ref DBUtility.ClsPub.sExeReturnInfo);
                        MessageBox.Show("单据号:" + DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("生产订单号")].Value) + " 删除成功!", "提示");
                    }
                }
                Display();
            }
            catch (Exception e)
            {
                MessageBox.Show("单据号:" + DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("生产订单号")].Value) + " 删除失败!"+e.ToString(), "提示");
            }
        }
 
        //选中行是否正常
        private bool AllowRow()
        {
            if (grdMain.CurrentRow == null)
            {
                return false;
            }
            if (grdMain.CurrentRow.Index >= 0 && grdMain.CurrentRow.Index <= grdMain.RowCount - 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        //打印
        GridppReport Report;
        private void btnFQBD_Click(object sender, EventArgs e)
        {
            string HLogoName = "";
            string sOpenTmp="在线打包";
            string HSourceBillNo2 =  DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("生产订单号")].Value);
            DataSet DS;
            DS = oWeb.getDataSetBySQL("exec h_p_FindCustTopFour  '" + HSourceBillNo2 + "'", "h_p_FindCustTopFour", ref DBUtility.ClsPub.sExeReturnInfo);
            if (DS == null || DS.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("获取打印模板失败!");
                return;
            }
            else
            {
                string Cust = ClsPub.isStrNull(DS.Tables[0].Rows[0][0]);
                HLogoName = "-" + Cust;
            }
 
            if (!Sub_SetReportList(sOpenTmp + HLogoName))
            {
                return;
            }
            Report.PrintPreview(false);
            Thread.Sleep(500);
        }
        protected double AllQty = 0;
        protected string str = "";
        private bool Sub_SetReportList(string sOpenTmp)
        {
            //判断行数
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                grdMain.Rows[i].Cells[0].Value = "";
            }
            for (int i = 0; i < grdMain.SelectedRows.Count; i++)
            {
                grdMain.Rows[grdMain.SelectedRows[i].Index].Cells[0].Value = "*";
                AllQty += DBUtility.ClsPub.isDoule(grdMain.Rows[grdMain.SelectedRows[i].Index].Cells[Fun_GetCol("数量")].Value);
                //判断多行补打时包装单号是否唯一
                string str2 = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.SelectedRows[i].Index].Cells[Fun_GetCol("包装单号")].Value);
                if (i==0)
                {
                    str = str2;
                }
                else if (i>0)
                {
                    if (!str.Equals(str2))
                    {
                        str = "";
                        MessageBox.Show("包装单号不唯一,请重新选择!");
                        return false;
                    }
                }
            }
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecordList);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTableList);
            //Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
            return true;
        }
 
        private void ReportBeforePostRecordList()
        {
            try
            {
                //Report.FieldByName("源单单号").AsString = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("包装单号")].Value);
                //Report.FieldByName("制单人").AsString = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("制单人")].Value);
                //Report.FieldByName("制单日期").AsString = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("制单日期")].Value);
                Report.FieldByName("源单单号").AsString = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("生产订单号")].Value);
                //Report.FieldByName("源单类型").AsString = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("源单类型")].Value);
                Report.FieldByName("总重量").AsString = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("总重量")].Value);
                AllQty = 0;
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表头:" + e.Message);
            }
        }
 
        private void ReportFetchRecordByDataTableList()
        {
            try
            {
                DataTable ds = new DataTable();
                SCM.Utility.FillRecordToReport(Report, grdMain, ds, Fun_GetCol("选择"));
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表体:" + e.Message);
            }
        }
 
        private void label2_Click(object sender, EventArgs e)
        {
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            //根据源单号,更新物流信息 
            oWeb.getRunProc("EXEC h_p_Sc_PackUnionBillMainForUpdate '" + DBUtility.ClsPub.isStrNull(txtHSourceBillNo.Text) + "'", ref DBUtility.ClsPub.sExeReturnInfo);
 
            //刷新
            Display();
        }
 
        private void cmdDataOut_Click(object sender, EventArgs e)
        {
            //DataGridViewToExcel2(grdMain, this.Text, this.Text);
            BLL.ClsPub_BLL.DataGridViewToExcel2(grdMain, this.Text);
        }
    }
}