雅琪诺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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace SCM.报表
{
    public partial class Qk_ProcessbillMain : Form
    {
        public Qk_ProcessbillMain()
        {
            InitializeComponent();
            dateTimePicker1.Text = DateTime.Now.AddDays(-7).ToString();
            dateTimePicker2.Text = DateTime.Now.ToString();
            oWeb.Url = SCM.ClsPub1.WEBSURL;
        }
        public frmBillQueryCondition_Base frmCondition;
        public string ViewName = "背景管制报表";
        public string ModCaption = "背景管制报表";
        public const string ModName = "1250";
        public string sDlgWhere = "";  //外窗体递入
        public int selectRow = 0;
        Pub_Class.ClsGridListSum oSumGrid = new Pub_Class.ClsGridListSum();
        SCM.WMSWeb.WebService1 oWeb = new SCM.WMSWeb.WebService1();
        private void yl_Click(object sender, EventArgs e)
        {
            DataGridViewToExcel2(grdMain, this.Text, this.Text);
        }
 
        private void cx_Click(object sender, EventArgs e)
        {
            Display();
        }
        private void Display()
        {
            StringBuilder whereBuilder = new StringBuilder();
            if (string.IsNullOrEmpty(dateTimePicker1.Text) || string.IsNullOrEmpty(dateTimePicker2.Text))
            {
                MessageBox.Show("输入时间不能为空");
                return;
            }
            if (DateTime.Parse(dateTimePicker1.Text) > DateTime.Parse(dateTimePicker2.Text))
            {
                MessageBox.Show("开始时间不能大于截至时间");
                return;
            }
            var execSql = "exec " + ViewName + " '"+ dateTimePicker1.Text + "','"+dateTimePicker2.Text+"','"+ txtHBillNo.Text + "','"+ textBox3.Text+ "','"+ textBox4.Text+ "','"+ textBox1.Text + "','"+ textBox2.Text + "'";
            oWeb.Timeout = 300000;
            DataSet DSet = oWeb.getDataSetBySQL(execSql, ViewName, ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
            {
                MessageBox.Show("没有返回任何结果" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdMain.DataSource = DSet.Tables[0].DefaultView;
            grdMain.RowHeadersVisible = false;
            ////设置合计列
            string sTotalCol = "";
            sTotalCol = DBUtility.Gy_BaseFun.GetTotalCols(DSet);
            string[] sT;
            sT = sTotalCol.Split(Convert.ToChar(","));
            oSumGrid.BuildTotalCols(sT);
            Total();
 
        }
 
 
        //合计 new
        private void Total()
        {
            if (grdMain.Rows.Count > 0 && grdMain.ColumnCount > 0)
            {
                oSumGrid.SetGridsum();
                oSumGrid.TotalAll();
            }
        }
 
 
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 网格 导出EXCEL   网格,文件名,标题名
        /// </summary>
        public static void DataGridViewToExcel2(DataGridView grdMain, string sText, string sBTText)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Execl文件(*.xls)|*.xls";
            saveFileDialog.FilterIndex = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt = true;
            saveFileDialog.Title = "数据视图导出EXCEL文件";
            saveFileDialog.FileName = sText;
            //saveFileDialog.ShowDialog();
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stream myStream;
                myStream = saveFileDialog.OpenFile();
                StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
                string str = "";
                DateTime start = DateTime.Now;
                try
                {
                    if (sBTText != "")
                    {
                        sw.WriteLine(sBTText);
                    }
                    //写标题
                    bool sFirstCol = true;
                    for (int i = 0; i < grdMain.ColumnCount; i++)
                    {
                        if (i > 0 && grdMain.Columns[i].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[i].HeaderText.Substring(0, 1) != "H" && sFirstCol != true)
                        {
                            str += "\t";
                        }
                        if (grdMain.Columns[i].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[i].HeaderText.Substring(0, 1) != "H")
                        {
                            sFirstCol = false;
                            str += grdMain.Columns[i].HeaderText;
                        }
                    }
                    str = str.Replace("\n", "");
                    sw.WriteLine(str);
 
                    //写内容
                    for (int j = 0; j < grdMain.Rows.Count; j++)
                    {
                        string tempStr = "";
                        sFirstCol = true;
                        for (int k = 0; k < grdMain.Columns.Count; k++)
                        {
                            if (k > 0 && grdMain.Columns[k].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[k].HeaderText.Substring(0, 1) != "H" && sFirstCol != true)
                            {
                                tempStr += "\t";
                            }
                            if (grdMain.Columns[k].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[k].HeaderText.Substring(0, 1) != "H")
                            {
                                sFirstCol = false;
                                if (grdMain.Rows[j].Cells[k].Value == null)
                                {
                                    tempStr += string.Empty;
                                }
                                else
                                {
                                    tempStr += grdMain.Rows[j].Cells[k].Value.ToString();
                                }
                            }
                        }
                        tempStr = tempStr.Replace("\n", "");
                        sw.WriteLine(tempStr);
                    }
                    sw.Close();
                    myStream.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    sw.Close();
                    myStream.Close();
                }
                MessageBox.Show("将此工作表导出为excel共耗时:" + DateTime.Now.Subtract(start).TotalMilliseconds.ToString() + "毫秒");
            }
        }
 
        private void grdMain_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            if (e.RowIndex < grdMain.Rows.Count)
            {
                DataGridViewRow dgrSingle = grdMain.Rows[e.RowIndex];
                try
                {
                    var rowIndex = DBUtility.Xt_BaseBillFun.Fun_GetCol("订单预计交货时间", grdMain);
                    if (dgrSingle.Cells[rowIndex].Value == null)
                        return;
                    var pusTimeStr = dgrSingle.Cells[rowIndex].Value.ToString().Trim();//获取数量
                    if (string.IsNullOrEmpty(pusTimeStr))
                        return;
                    if (DateTime.Parse(pusTimeStr) < DateTime.Now)
                    {
                        // 设置单元格的背景色
                        dgrSingle.DefaultCellStyle.BackColor = Color.FromArgb(255, 128, 128);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
 
        private void Qk_ProcessbillMain_Load(object sender, EventArgs e)
        {
            oSumGrid.ogrdMain = grdMain;  //初始化 new
            oSumGrid.oGridsum = grdSum;
        }
    }
}