private void UpdateUI(int status) { switch (status) { case (int)ProcessStatus.Status_None: groupBox_Info.Enabled = true; Info_listView1.Enabled = true; Info_listView1.Clear(); button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; break; case (int)ProcessStatus.Status_Connect: groupBox_Info.Enabled = true; Info_listView1.Enabled = true; //Info_listView1.Clear(); button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; break; case (int)ProcessStatus.Status_Start: groupBox_Info.Enabled = false; Info_listView1.Enabled = false; //Info_listView1.Clear(); button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; break; case (int)ProcessStatus.Status_Finish: groupBox_Info.Enabled = true; Info_listView1.Enabled = true; //Info_listView1.Clear(); button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; break; } }
private void button3_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "Select script file"; dialog.InitialDirectory = Application.StartupPath; dialog.Filter = "xls file (*.*)|*.xls"; if (dialog.ShowDialog() == DialogResult.OK) { globalVar.ScriptPath = dialog.FileName; } else { return; } string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + globalVar.ScriptPath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;Mode=Read'"; OleDbConnection ODConn; ODConn = new OleDbConnection(ConnStr); try { ODConn.Open(); } catch { } globalVar.CommandList.Clear(); Info_listView1.Clear(); string strSql = "SELECT * FROM[Script$]"; int ScriptCommandCount = 0; string ScriptCommandURL = ""; OleDbCommand ODCmd = ODConn.CreateCommand(); ODCmd.CommandText = strSql; DataSet myDataSet = new DataSet(); OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSql, ODConn); MyAdapter.Fill(myDataSet, "Script"); DataTable dt = myDataSet.Tables["Script"]; foreach (DataRow dr in dt.Rows) { ScriptCommandURL = ""; if (dr["Case"].ToString() == "") { return; } if (Convert.ToInt32(dr["Case"].ToString()) == ScriptCommandCount + 1) { switch (dr["Type"].ToString()) { case "Command": ScriptCommandCount++; ScriptCommandURL = String.Concat("http://192.168.1.254/?custom=1&cmd=", dr["ID"].ToString()); if (dr["Parameter"].ToString() != "" && dr["Parameter"].ToString() != "NULL") { if (dr["Parameter Type"].ToString() == "par") { ScriptCommandURL = String.Concat(ScriptCommandURL, "&par=", dr["Parameter"].ToString()); } else if (dr["Parameter Type"].ToString() == "str") { ScriptCommandURL = String.Concat(ScriptCommandURL, "&str=", dr["Parameter"].ToString()); } Info_listView1.Items.Add(dr["ID"].ToString() + " , " + dr["Parameter"].ToString()); } else { Info_listView1.Items.Add(dr["ID"].ToString()); } break; case "Liveview": ScriptCommandCount++; if (dr["Parameter"].ToString() != "" && dr["Parameter"].ToString() != "NULL") { ScriptCommandURL = String.Concat("http://192.168.1.254:", dr["Parameter"].ToString()); } else { ScriptCommandURL = String.Concat("http://192.168.1.254:", "8192"); } Info_listView1.Items.Add("Liveview"); break; case "FileSystem": ScriptCommandCount++; if (dr["ID"].ToString() != "") { ScriptCommandURL = String.Concat("http://192.168.1.254/", dr["ID"].ToString()); if (dr["Parameter"].ToString() == "0") { ScriptCommandURL = String.Concat(ScriptCommandURL, "?del=1"); } } Info_listView1.Items.Add("FileSystem"); break; case "Connect": ScriptCommandCount++; ScriptCommandURL = "Connect," + dr["ID"].ToString() + "," + dr["Parameter"].ToString(); Info_listView1.Items.Add("Connect" + " , " + dr["ID"].ToString() + " , " + dr["Parameter"].ToString()); break; case "Socket": ScriptCommandCount++; ScriptCommandURL = "Socket," + dr["Parameter"].ToString(); Info_listView1.Items.Add("Socket" + " , " + dr["Parameter"].ToString()); break; case "Delay": ScriptCommandCount++; ScriptCommandURL = "Delay," + dr["Parameter"].ToString(); Info_listView1.Items.Add("Delay" + " , " + dr["Parameter"].ToString()); break; case "Thumb": ScriptCommandCount++; if (dr["ID"].ToString() != "") { ScriptCommandURL = String.Concat("http://192.168.1.254/", dr["ID"].ToString(), "?custom=1&cmd=6003"); Info_listView1.Items.Add("Thumb" + " , " + dr["ID"].ToString()); } break; } globalVar.CommandList.Add(ScriptCommandURL); Info_listView1.Refresh(); } } }