码迷,mamicode.com
首页 > 其他好文 > 详细

社会单位消防安全户籍化管理系统——半自动提交V1.0版本

时间:2018-05-12 23:55:07      阅读:1817      评论:0      收藏:0      [点我收藏+]

标签:java   cas   次数   timer   switch   inf   办公   object   ESS   

社会单位消防安全户籍化管理系统——半自动提交V1.0版本

  • 首先先上代码,开发这个小程序其实是用来帮助同事完成一项每天都做的繁琐事件,以往需要花费十分钟做这件事情,现在就是傻瓜式,点几下鼠标就好了。本来想写成每天自动化定时执行任务,但使用此小程序的同事已离职,不再使用这项功能了,也就懒得再继续更新维护了。
  • 这个小程序原理很简单,就是利用C#WebBrowser控件进行提交内容。
  • 可能用javascript编写会更快吧,编写的时候,正好在练习使用WebBrowser控件。
  • 编程嘛,在没有强制要求的时候,随心所欲咯,js、python等都可以写,或许更快。
  • 总之能解决问题的方法都是好方法。
  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Threading.Tasks;
  9 using System.Windows.Forms;
 10 using mshtml;
 11 
 12 namespace 消防半自动提交
 13 {
 14     public partial class frmMain : Form
 15     {
 16         int XCXZ = 0;//巡查新增判断数值
 17         public frmMain()
 18         {
 19             InitializeComponent();
 20         }
 21 
 22         ///http://www.cnblogs.com/Hackerman/p/4964816.html C#WebBrowser控件使用教程与技巧
 23         /// <summary>
 24         /// 窗体加载
 25         /// </summary>
 26         /// <param name="sender"></param>
 27         /// <param name="e"></param>
 28         private void frmMain_Load(object sender, EventArgs e)
 29         {
 30             webBrowser1.Navigate("http://110.249.133.4:85/FrameSet/Login.aspx", false);//默认加载消防安全户籍管理系统
 31             toolStripLabel1.Text = GetDate();//显示日期
 32 
 33             button1.Visible = false;
 34             button2.Visible = false;
 35             textBox1.Visible = false;
 36             toolStripButton1.Visible = false;
 37 
 38 
 39 
 40 
 41         }
 42         /// <summary>
 43         /// 获取当前时间并格式化
 44         /// </summary>
 45         /// <returns></returns>
 46         private string GetDate()
 47         {
 48             return DateTime.Now.Date.ToString("yMMdd").Remove(0,1);//获取日期并截取
 49         }
 50 
 51         /// <summary>
 52         /// http://110.249.133.4:85/JCDAPage/XFGZJLPage/XKSZBJLBAddPage.aspx 新增消防控制室值班记录,主要提交表单
 53         /// </summary>   
 54         /// string dd = DateTime.Now.Date.ToString("yMMdd").Remove(0, 1);
 55         private void SendXKSZBJLBAddPage()
 56         {
 57             //webBrowser1.Url.ToString();
 58             if (webBrowser1.Url.ToString() == "http://110.249.133.4:85/JCDAPage/XFGZJLPage/XKSZBJLBAddPage.aspx")
 59             {
 60                 webBrowser1.Document.GetElementById("ctl00_MainContent_txt_XH").InnerText = GetDate();
 61                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxt_TBRQ").InnerText = DateTime.Now.Date.ToString("yyyy-MM-dd");
 62                 webBrowser1.Document.GetElementById("ctl00_MainContent_txt_ZRRQM").InnerText = "小李";
 63                 webBrowser1.Document.GetElementById("ctl00_MainContent_txt_XKSMC").InnerText = "消防控制室";
 64                 webBrowser1.Document.GetElementById("ctl00_MainContent_ch_ZC").SetAttribute("Checked", "True");
 65                 webBrowser1.Document.GetElementById("ctl00_MainContent_cb_ZD").SetAttribute("Checked", "True");
 66                 webBrowser1.Document.GetElementById("ctl00_MainContent_cb_QTZC").SetAttribute("Checked", "True");
 67                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxt_ZBY").InnerText = "正常";
 68                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxt_ZBPC").InnerText = "2";
 69                 webBrowser1.Document.GetElementById("ctl00_MainContent_cb_ZJ").SetAttribute("Checked", "True");
 70                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxt_JCR").InnerText = "小李";
 71                 //webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContentbtnBC").InvokeMember("Click");
 72                 webBrowser1.Document.GetElementById("ctl00_MainContent_btnBC").InvokeMember("Click");
 73             }
 74             else
 75             {
 76                 //MessageBox.Show("错误");
 77             }
 78             
 79             
 80            
 81         }
 82         /// <summary>
 83         ///http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXC_SimpleAddPage.aspx 每日防火巡查记录表,主要提交表单
 84         /// </summary>
 85         private void SendFHXC_SimpleAddPage()
 86         {
 87             if (webBrowser1.Url.ToString() == "http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXC_SimpleAddPage.aspx")
 88             {
 89                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtRQ").InnerText = DateTime.Now.Date.ToString("yyyy-MM-dd");//巡查日期
 90                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtBH").InnerText = GetDate();//编号
 91                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCY").InnerText = "小李";//巡查员
 92                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCCS").InnerText = "6";//巡查次数
 93                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtFXWT").InnerText = "正常";//巡查总体情况
 94                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtJCR").InnerText = "小李";//核查人
 95                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtZGR").InnerText = "小李";//主管人
 96                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtJCRQ").InnerText = DateTime.Now.Date.ToString("yyyy-MM-dd");//巡查日期
 97 
 98                 webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContentbtnAdd").InvokeMember("Click");
 99                 //webBrowser1.Document.GetElementById("ctl00_MainContent_btnBC").InvokeMember("Click");
100             }
101             else
102             {
103                 //MessageBox.Show("错误");
104             }
105         }
106         /// <summary>
107         /// http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLListPage.aspx 每日防火巡查情况汇总,需要获取维护地址。
108         /// </summary>
109         /// 获取维护地址
110         private string GetXCID()
111         {
112 
113             if (webBrowser1.Url.ToString() == "http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLListPage.aspx")
114             {
115                 if (webBrowser1.Document.GetElementById("ctl00_MainContent_gridFHXC") != null)
116                 {
117                     HtmlElement he = webBrowser1.Document.GetElementById("ctl00_MainContent_gridFHXC");
118                      XCID = he.GetElementsByTagName("a")[2].GetAttribute("search");
119 
120                     //he.InnerHtml;
121                 }
122                 
123 
124             }
125             else
126             {
127                 //MessageBox.Show("错误");
128             }
129             return XCID;
130              
131 
132         }
133         /// <summary>
134         /// http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLNRAddPage.aspx?XCID=29BB093D0158471496FB8B77AA87B25C 单日巡查情况维护
135         /// </summary>
136         /// 每日防火巡查记录表添加,需要添加6次
137         private void SendFHXCJLNRAddPage()
138         {
139             
140 
141 
142                 if (XCXZ == 0)
143                     {
144                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCSJ").InnerText = "08时00分";//巡查时间
145                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCJSSJ").InnerText = "8时30分";
146                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCBW").InnerText = "库房";//巡查部位
147                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtCLQK").InnerText = "正常";
148                         webBrowser1.Document.GetElementById("ctl00_MainContent_btnAdd").InvokeMember("Click");
149                         XCXZ = XCXZ + 1;
150 
151                     }
152                     else if(XCXZ == 1)
153                     {
154                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCSJ").InnerText = "9时00分";//巡查时间
155                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCJSSJ").InnerText = "9时30分";
156                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCBW").InnerText = "厨房";//巡查部位
157                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtCLQK").InnerText = "正常";
158                         webBrowser1.Document.GetElementById("ctl00_MainContent_btnAdd").InvokeMember("Click");
159                         XCXZ = XCXZ + 1;
160                     }
161                     else if (XCXZ == 2)
162                     {
163                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCSJ").InnerText = "10时00分";//巡查时间
164                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCJSSJ").InnerText = "10时30分";
165                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCBW").InnerText = "餐厅";//巡查部位
166                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtCLQK").InnerText = "正常";
167                         webBrowser1.Document.GetElementById("ctl00_MainContent_btnAdd").InvokeMember("Click");
168                         XCXZ = XCXZ + 1;
169                     }
170                     else if (XCXZ == 3)
171                     {
172                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCSJ").InnerText = "14时00分";//巡查时间
173                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCJSSJ").InnerText = "14时30分";
174                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCBW").InnerText = "办公室";//巡查部位
175                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtCLQK").InnerText = "正常";
176                         webBrowser1.Document.GetElementById("ctl00_MainContent_btnAdd").InvokeMember("Click");
177                          XCXZ = XCXZ + 1;
178                     }
179                     else if (XCXZ == 4)
180                     {
181                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCSJ").InnerText = "15时00分";//巡查时间
182                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCJSSJ").InnerText = "15时30分";
183                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCBW").InnerText = "前厅";//巡查部位
184                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtCLQK").InnerText = "正常";
185                         webBrowser1.Document.GetElementById("ctl00_MainContent_btnAdd").InvokeMember("Click");
186                          XCXZ = XCXZ + 1;
187                     }
188                     else if (XCXZ == 5)
189                     {
190                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCSJ").InnerText = "16时00分";//巡查时间
191                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCJSSJ").InnerText = "16时30分";
192                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCBW").InnerText = "客房";//巡查部位
193                         webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtCLQK").InnerText = "正常";
194                         webBrowser1.Document.GetElementById("ctl00_MainContent_btnAdd").InvokeMember("Click");
195                          XCXZ = XCXZ + 1;
196                     }
197 
198                     
199 
200                 
201            
202         }
203 
204      
205 
206         private void toolStripButton5_Click(object sender, EventArgs e)
207         {
208             if (webBrowser1.Url.ToString() == "http://110.249.133.4:85/FrameSet/Login.aspx")
209             {
210                 webBrowser1.Document.GetElementById("txtUserName").InnerText = "admin";//登陆用户名
211                 webBrowser1.Document.GetElementById("txtPwd").InnerText = "123";//登陆密码
212             }
213             else
214             {
215                 //没有结果
216             }
217         }
218 
219         private void toolStripButton4_Click(object sender, EventArgs e)
220         {
221             webBrowser1.Navigate("http://110.249.133.4:85/JCDAPage/XFGZJLPage/XKSZBJLBAddPage.aspx", false);
222 
223             //SendXKSZBJLBAddPage();
224 
225 
226             
227         }
228 
229         private void button1_Click(object sender, EventArgs e)
230         {
231             ////webBrowser1.Navigate("http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLListPage.aspx", false);
232             ////SendXKSZBJLBAddPage();
233             //webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCSJ").InnerText = "08时00分";//巡查时间
234             //webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCJSSJ").InnerText = "8时30分";
235             //webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtXCBW").InnerText = "库房";//巡查部位
236             //webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContenttxtCLQK").InnerText = "正常";
237             XCID = textBox1.Text;
238             
239             
240 
241         }
242 
243         private void button2_Click(object sender, EventArgs e)
244         {
245             webBrowser1.Document.GetElementById("ctl00MainContent" role="presentation">MainContentMainContentMainContentbtnFH").InvokeMember("Click");
246         }
247 
248         private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
249         {
250             //自动点击弹出确认或弹出提示
251 
252             IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
253 
254             vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); //弹出确认
255 
256             vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");//弹出提示
257 
258             
259 
260         }
261 
262         private void timer1_Tick(object sender, EventArgs e)
263         {
264 
265         }
266         /// <summary>
267         /// webBrowser网页加载完后判断执行
268         /// </summary>
269         /// <param name="sender"></param>
270         /// <param name="e"></param>
271         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
272         {
273             if (webBrowser1.Url.ToString()== "http://110.249.133.4:85/FrameSet/Login.aspx")
274             {
275                 webBrowser1.Document.GetElementById("txtUserName").InnerText = "admin";//登陆用户名
276                 webBrowser1.Document.GetElementById("txtPwd").InnerText = "123";//登陆密码
277             }
278             else if (webBrowser1.Url.ToString() == "http://110.249.133.4:85/JCDAPage/XFGZJLPage/XKSZBJLBAddPage.aspx")
279             {
280                 SendXKSZBJLBAddPage();
281             }
282             else if (webBrowser1.Url.ToString() == "http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXC_SimpleAddPage.aspx")
283             {
284                 SendFHXC_SimpleAddPage();
285             }
286             else if (webBrowser1.Url.ToString() == "http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLListPage.aspx")
287             {
288                 GetXCID();
289                 toolStripLabel1.Text = XCID;
290                 //textBox1.Text = XCID;
291 
292             }
293             else if(XCID!=null)
294             {
295                 if (webBrowser1.Url.ToString() == "http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLNRAddPage.aspx" + XCID)//加个判断
296                 {
297                     SendFHXCJLNRAddPage();
298 
299                 }
300                 else if(webBrowser1.Url.ToString() == "http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLNRListPage.aspx" + XCID)//返回汇总列表的触发
301                 {
302                     //for (XCXZ = 1; XCXZ < 6; XCXZ++)
303                     //{
304                     //    SendFHXCJLNRAddPage();
305                     //}
306                     SendFHXCJLNRAddPage();
307                     
308                 }
309                 else
310                 {
311                     //希望不出错哈哈
312                 }
313             }
314             else
315             {
316                 //希望不出错
317             }
318            
319         }
320 
321         private void toolStripButton3_Click(object sender, EventArgs e)
322         {
323             webBrowser1.Navigate("http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXC_SimpleAddPage.aspx", false);
324         }
325 
326         private void toolStripButton2_Click(object sender, EventArgs e)
327         {
328             webBrowser1.Navigate("http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLNRAddPage.aspx" + XCID, false);
329             
330             switch (XCXZ)
331             {
332                 case 0:
333                     toolStripButton2.Text = ("5、单日巡查情况维护,点击了" + (XCXZ + 1) + "");
334                     //XCXZ =XCXZ+1;
335                     break;
336                 case 1:
337                     toolStripButton2.Text = ("5、单日巡查情况维护,点击了" + (XCXZ + 1) + "");
338                     //XCXZ = XCXZ + 1;
339                     break;
340                 case 2:
341                     toolStripButton2.Text = ("5、单日巡查情况维护,点击了" + (XCXZ + 1) + "");
342                     //XCXZ = XCXZ + 1;
343                     break;
344                 case 3:
345                     toolStripButton2.Text = ("5、单日巡查情况维护,点击了" + (XCXZ + 1) + "");
346                     //XCXZ = XCXZ + 1;
347                     break;
348                 case 4:
349                     toolStripButton2.Text = ("5、单日巡查情况维护,点击了" + (XCXZ + 1) + "");
350                     //XCXZ = XCXZ + 1;
351                     break;
352                 case 5:
353                     toolStripButton2.Text = ("5、单日巡查情况维护,点击了" + (XCXZ + 1) + "");
354                     //XCXZ = XCXZ + 1;
355                     toolStripButton2.Visible = false;
356                     break;
357                 default:
358                     break;
359             }
360 
361         }
362         /// <summary>
363         /// 获取维护ID
364         /// </summary>
365         /// <param name="sender"></param>
366         /// <param name="e"></param>
367         private void toolStripButton6_Click(object sender, EventArgs e)
368         {
369             webBrowser1.Navigate("http://110.249.133.4:85/JCDAPage/XFGZJLPage/FHXCJLListPage.aspx", false);
370         
371 
372            
373         }
374 public string XCID { get; set; }
375         
376     }
377 }

 

下面是效果图,内部效果就不展示了。

技术分享图片

 

社会单位消防安全户籍化管理系统——半自动提交V1.0版本

标签:java   cas   次数   timer   switch   inf   办公   object   ESS   

原文地址:https://www.cnblogs.com/landv/p/9030582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!