private void ThreadAdd(PmsVehicleClass pvc) { BtnDelegate btn = new BtnDelegate(BtnTxt); LabelDelegate label = new LabelDelegate(LabelTxt); PrograDelegate Progra = new PrograDelegate(PrograStepup); int i = 1; foreach (KeyValuePair <string, string> kv in carpark) { if (ToolsUtility.Ping(kv.Value)) { this.Invoke(label, kv.Key, 1); this.Invoke(label, i.ToString() + "/" + carpark.Count.ToString(), 2); DBUtility.AddStaffIU(pvc, kv.Key, kv.Value); } this.Invoke(Progra); i++; } this.Invoke(btn); }
private void button1_Click(object sender, EventArgs e) { pBar1.Minimum = 1; pBar1.Maximum = carpark.Count; pBar1.Step = 1; if (button1.Text == "Start") { string user = name.Text.Trim(); if (ToolsUtility.CheckValue(IUtxt.Text.Trim(), rIUtxt.Text.Trim()) && ToolsUtility.CheckValue(plate.Text.Trim(), rplate.Text.Trim()) && ToolsUtility.CheckValue(name.Text.Trim(), rname.Text.Trim())) { PmsVehicleClass pvc = new PmsVehicleClass(); pvc.IU = IUtxt.Text.Trim(); pvc.Plate = plate.Text.Trim(); pvc.Name = name.Text.Trim(); pvc.ExpiredDate = dateTimePicker1.Value.ToString("yyyy-MM-dd ") + "00:00:00"; thr = new Thread(() => ThreadAdd(pvc)); thr.Start(); button1.Text = "Stop"; } else { MessageBox.Show("IU or vehicle or name Format Incorrect"); } } else if (button1.Text == "Stop") { if (thr != null) { if (thr.IsAlive) { thr.Abort(); } } button1.Text = "Start"; } }
//Add IU for Secure Parking Staff public static bool AddStaffIU(PmsVehicleClass vehicle, string dbname, string ipaddress) { string constr = "Data Source=" + ipaddress + ";uid=sa;pwd=yzhh2007;database=" + dbname + ";Connection Timeout=15"; string cmd = @"declare @x int select @x=(select count(*) from season_mst) if EXISTS(select * from season_mst where season_no=@IU) BEGIN UPDATE season_mst set s_status=1,date_to=@ExpiredDate,vehicle_no=@plate,holder_name=@name,holder_type=7,update_dt=GETDATE() where season_no=@IU END else BEGIN INSERT INTO [dbo].[season_mst](multi_season,rate_type,operator,season_id,season_type,s_status,holder_type,season_no,date_from,date_to,vehicle_no,add_dt,full_company) VALUES (1,0,'op',@x+1,2,1,7,@IU,@StartDate,@ExpiredDate,@plate,GETDATE(),'Secure Parking Singapore Pte Ltd') END;"; string startdate = DateTime.Now.ToString("yyyy-MM-dd ") + "00:00:00"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@IU", vehicle.IU), new SqlParameter("@plate", vehicle.Plate), new SqlParameter("@ExpiredDate", vehicle.ExpiredDate), new SqlParameter("@name", vehicle.Name), new SqlParameter("@StartDate", startdate) }; try { SqlHelper.ExecuteNonQuery(constr, CommandType.Text, cmd, para); LogClass.WirteLine("Delete StaffIU ok"); return(true); } catch (SqlException sqle) { LogClass.WirteLine(dbname + "Sql error when add StaffIU:" + sqle.ToString()); return(false); } }