Пример #1
0
        private void btnDelCommands_Click(object sender, EventArgs e)
        {
            string sql       = string.Format(@"select t.StationID from PandaDTU t where t.终端登录号码='{0}'", this.textTel.Text.Trim());
            string stationID = DBUtil.ExecuteScalar(sql, out string errMsg).ToString();

            if (!string.IsNullOrEmpty(errMsg))
            {
                ShowMessageAndAddLog(errMsg);
                return;
            }
            if (string.IsNullOrEmpty(stationID))
            {
                ShowMessageAndAddLog("未查询到电话号码为" + this.textTel.Text + "的记录");
                return;
            }
            //不能删除服务正在执行的任务
            string delSQL = string.Format(@"delete  PandaCommand where sensorID in (
                              select t.sensorID from PandaCommand t
                              left join Sensor tt on tt.ID=t.sensorID
                              where tt.StationID='{0}' and t.status  in ('未完成','任务成功','任务失败','任务超时'))", stationID);

            int rows = DBUtil.ExecuteNonQuery(delSQL, out errMsg);

            if (rows >= 0 && errMsg == "")
            {
                ShowMessageAndAddLog(string.Format("已成功删除{0}张操作票", rows.ToString()));
                LoadCommandsDetail();
            }
            else
            {
                ShowMessageAndAddLog("操作票删除失败");
            }
        }
Пример #2
0
        private void btn_creatSomeCommands_Click(object sender, EventArgs e)
        {
            string sql       = string.Format(@"select t.StationID from PandaDTU t where t.终端登录号码='{0}'", this.textTel.Text.Trim());
            string stationID = DBUtil.ExecuteScalar(sql, out string errMsg).ToString();

            if (!string.IsNullOrEmpty(errMsg))
            {
                ShowMessageAndAddLog(errMsg);
                return;
            }
            if (string.IsNullOrEmpty(stationID))
            {
                ShowMessageAndAddLog("未查询到电话号码为" + this.textTel.Text + "的记录");
                return;
            }
            string insertSQL = "";

            for (int i = 1; i <= (int)this.numeric_read.Value; i++)
            {
                insertSQL += string.Format("INSERT INTO PandaCommand (type, sensorID,status) VALUES ( '读','{0}','未完成');", i.ToString() + "-" + stationID);
            }
            for (int i = 1; i <= (int)this.numeric_write.Value; i++)
            {
                insertSQL += string.Format("INSERT INTO PandaCommand (type, sensorID,sensorValue,status) VALUES ( '写','{0}',{1}, '未完成');", i.ToString() + "-" + stationID, i);
            }
            int rows = DBUtil.ExecuteNonQuery(insertSQL, out errMsg);

            if (rows > 0 && errMsg == "")
            {
                ShowMessageAndAddLog(string.Format("已成功生成【{0}】张读操作票和【{1}】张写操作票",
                                                   this.numeric_read.Value.ToString(), this.numeric_write.Value.ToString()), MessageBoxIcon.Information);
                LoadCommandsDetail();
            }
            else
            {
                ShowMessageAndAddLog("操作票生成失败");
            }
        }