private void btnAdd_Click(object sender, EventArgs e) { EnableControl(); if (m_bllc.GetList("methodName='" + _method + "'", true).Tables[0].Rows.Count > 0) { //查询最后一项记录 m_modc = m_bllc.GetModelOfMaxID(_method); if (m_modc != null) { this.cmbAction.Text = ""; //取最后一条数据的时间点和持续时间 作为下一步骤的时间点 int sumTime = (int)m_modc.timeCount + (int)m_modc.timeSpan; int hour = (int)sumTime / 3600; int min = (int)(sumTime % 3600) / 60; int sec = (int)sumTime % 60; this.lblHour.Text = hour.ToString("00"); this.lblMin.Text = min.ToString("00"); this.lblSec.Text = sec.ToString("00"); this.lblHourc.Text = "00"; this.lblMinc.Text = "00"; this.lblSecc.Text = "00"; //持续时间自己定义 } } else { this.lblHour.Text = this.lblHourc.Text = this.lblMin.Text = this.lblMinc.Text = this.lblSec.Text = this.lblSecc.Text = "00"; } }
public ALS.Model.customactions GetModel(string methodName, string actionName) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID,methodName,timeCount,actionName,timeString,timeSpan,timeSpanString from tb_customactions "); strSql.Append(" where actionName=@actionName and methodName=@methodName "); MySqlParameter[] parameters = { new MySqlParameter("@actionName", MySqlDbType.VarChar), new MySqlParameter("@methodName", MySqlDbType.VarChar) }; parameters[0].Value = actionName; parameters[1].Value = methodName; ALS.Model.customactions model = new ALS.Model.customactions(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ALS.Model.customactions model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_customactions("); strSql.Append("methodName,timeCount,actionName,timeString,timeSpan,timeSpanString)"); strSql.Append(" values ("); strSql.Append("@methodName,@timeCount,@actionName,@timeString,@timeSpan,@timeSpanString)"); MySqlParameter[] parameters = { new MySqlParameter("@methodName", MySqlDbType.VarChar, 255), new MySqlParameter("@timeCount", MySqlDbType.Int32, 11), new MySqlParameter("@actionName", MySqlDbType.VarChar, 255), new MySqlParameter("@timeString", MySqlDbType.VarChar, 255), new MySqlParameter("@timeSpan", MySqlDbType.Int32, 11), new MySqlParameter("@timeSpanString", MySqlDbType.VarChar, 255), }; parameters[0].Value = model.methodName; parameters[1].Value = model.timeCount; parameters[2].Value = model.actionName; parameters[3].Value = model.timeString; parameters[4].Value = model.timeSpan; parameters[5].Value = model.timeSpanString; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ALS.Model.customactions model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_customactions set "); strSql.Append("methodName=@methodName,"); strSql.Append("timeCount=@timeCount,"); strSql.Append("actionName=@actionName,"); strSql.Append("timeString = @timeString,"); strSql.Append("timeSpan = @timeSpan,"); strSql.Append("timeSpanString=@timeSpanString,"); strSql.Append("tipPic = @tipPic"); strSql.Append(" where ID=@ID"); MySqlParameter[] parameters = { new MySqlParameter("@methodName", MySqlDbType.VarChar, 255), new MySqlParameter("@timeCount", MySqlDbType.Int32, 11), new MySqlParameter("@actionName", MySqlDbType.VarChar, 255), new MySqlParameter("@timeString", MySqlDbType.VarChar, 255), new MySqlParameter("@timeSpan", MySqlDbType.Int32, 11), new MySqlParameter("@timeSpanString", MySqlDbType.VarChar, 255), new MySqlParameter("@tipPic", MySqlDbType.LongBlob), new MySqlParameter("@ID", MySqlDbType.Int32, 11) }; parameters[0].Value = model.methodName; parameters[1].Value = model.timeCount; parameters[2].Value = model.actionName; parameters[3].Value = model.timeString; parameters[4].Value = model.timeSpan; parameters[5].Value = model.timeSpanString; parameters[6].Value = model.tipPic; parameters[7].Value = model.ID; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void dgCustomAction_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { UnEnableControl(); this.lblHourc.Enabled = true; this.lblMinc.Enabled = true; this.lblSecc.Enabled = true; this.tabActions.Enabled = true; this.btnUpdate.Enabled = true; m_customID = Convert.ToInt32(dgvCustomActions.Rows[e.RowIndex].Cells["ID"].Value.ToString()); //获取该步骤信息 ALS.BLL.customactions bllc = new ALS.BLL.customactions(); m_modc = bllc.GetModel(m_customID); if (m_modc != null) { this.cmbAction.Text = m_modc.actionName; this.cmbAction.Text = m_modc.actionName; this.lbltsPump.Text = Cls.utils.SecondsToTime((int)m_modc.timeSpan); int hour = (int)m_modc.timeCount / 3600; int min = (int)(m_modc.timeCount % 3600) / 60; int sec = (int)m_modc.timeCount % 60; this.lblHour.Text = hour.ToString("00"); this.lblMin.Text = (min).ToString("00"); this.lblSec.Text = sec.ToString("00"); int hourc = (int)m_modc.timeSpan / 3600; int minc = (int)(m_modc.timeSpan % 3600) / 60; int secc = (int)(m_modc.timeSpan % 60); this.lblHourc.Text = hourc.ToString("00"); this.lblMinc.Text = minc.ToString("00"); this.lblSecc.Text = secc.ToString("00"); } //获取该时间点作列表 ShowActions(m_customID); } else { m_customID = -1; m_modc = null; this.tabActions.Enabled = false; } }
private void btnDel_Click(object sender, EventArgs e) { m_modc = m_bllc.GetModelOfMaxID(_method); if (m_modc != null) { if (DialogResult.OK == MessageBox.Show("确认删除步骤: " + m_modc.actionName + " ?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)) { m_bllc.Delete(m_modc.ID); ShowCustomActions(_method); this.lblHourc.Text = this.lblMinc.Text = this.lblSecc.Text = "00"; this.cmbAction.Text = ""; m_modc = null; } } else { MessageBox.Show("无删除项!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
/// <summary> /// 得到一个对象实体 /// </summary> public ALS.Model.customactions DataRowToModel(DataRow row) { ALS.Model.customactions model = new ALS.Model.customactions(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = long.Parse(row["ID"].ToString()); } if (row["methodName"] != null) { model.methodName = row["methodName"].ToString(); } if (row["timeCount"] != null && row["timeCount"].ToString() != "") { model.timeCount = int.Parse(row["timeCount"].ToString()); } if (row["timeSpan"] != null && row["timeSpan"].ToString() != "") { model.timeSpan = int.Parse(row["timeSpan"].ToString()); } if (row["actionName"] != null) { model.actionName = row["actionName"].ToString(); } if (row["timeString"] != null) { model.timeString = row["timeString"].ToString(); } if (row["timeSpanString"] != null) { model.timeString = row["timeSpanString"].ToString(); } if (row["tipPic"] != null && row["tipPic"].ToString() != "") { model.tipPic = (byte[])row["tipPic"]; } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public ALS.Model.customactions GetModelOfMaxID(string _methodName) { StringBuilder strSql = new StringBuilder(); strSql.Append("select max(ID) from tb_customactions "); strSql.Append("where methodName='" + _methodName + "'"); DataSet ds = DbHelperMySQL.Query(strSql.ToString()); int ID = 0; if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["max(ID)"].ToString())) { ID = Convert.ToInt32(ds.Tables[0].Rows[0]["max(ID)"].ToString()); } ALS.Model.customactions model = GetModel(ID); if (model != null) { return(model); } else { return(null); } }
private void btnUpdate_Click(object sender, EventArgs e) { int hourc = int.Parse(this.lblHourc.Text); int minc = int.Parse(this.lblMinc.Text); int secc = int.Parse(this.lblSecc.Text); int timespan = hourc * 3600 + minc * 60 + secc; if (timespan == 0) { MessageBox.Show("持续时间不能为 0 ", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ALS.BLL.customactions bllcustom = new ALS.BLL.customactions(); ALS.Model.customactions modelcustom = bllcustom.GetModel(this._method, this.cmbAction.Text.Trim()); //CustomActions.BLL.actions bllaction = new CustomActions.BLL.actions(); //DataSet dsaction = bllaction.GetList("customID='"+ modelcustom.ID+"'"); //先查询该时间点是否有重复的 if (modelcustom != null) { //m_modc = new CustomActions.Model.customactions(); modelcustom.timeString = Cls.utils.SecondsToTime(0); modelcustom.actionName = this.cmbAction.Text.Trim(); modelcustom.methodName = _method; modelcustom.timeCount = 0; modelcustom.timeSpan = timespan; modelcustom.timeSpanString = Cls.utils.SecondsToTime(timespan); m_bllc = new ALS.BLL.customactions(); if (m_bllc.Update(modelcustom)) { //刷新列表,sort by timecount ShowCustomActions(_method); UnEnableControl(); } } }
/// <summary> /// 得到一个对象实体 /// </summary> public ALS.Model.customactions GetModel(long ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID,methodName,timeCount,actionName,timeString,timeSpan,timeSpanString from tb_customactions "); strSql.Append(" where ID=@ID"); MySqlParameter[] parameters = { new MySqlParameter("@ID", MySqlDbType.Int32) }; parameters[0].Value = ID; ALS.Model.customactions model = new ALS.Model.customactions(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void btnSave_Click(object sender, EventArgs e) { //int hour = int.Parse(this.lblHour.Text); //int min = int.Parse(this.lblMin.Text); //int sec = int.Parse(this.lblSec.Text); //int timecount = hour * 3600 + min * 60 + sec; int hourc = int.Parse(this.lblHourc.Text); int minc = int.Parse(this.lblMinc.Text); int secc = int.Parse(this.lblSecc.Text); int timespan = hourc * 3600 + minc * 60 + secc; //if (!this.txtAction.Enabled) //{ // MessageBox.Show("请点击'输入步骤'按钮", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} //if (string.IsNullOrEmpty(this.txtAction.Text)) //{ // MessageBox.Show("请输入该步骤描述信息", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} if (string.IsNullOrEmpty(this.cmbAction.Text)) { MessageBox.Show("请输入该步骤描述信息", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (timespan == 0) { if (DialogResult.OK == MessageBox.Show("持续时间为0,点确定将添加为提示信息!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)) { //添加的是一个提示框 m_modc = new ALS.Model.customactions(); m_modc.timeString = Cls.utils.SecondsToTime(0); m_modc.actionName = this.cmbAction.Text.Trim(); m_modc.methodName = _method; m_modc.timeCount = 0; m_modc.timeSpan = 0; m_modc.timeSpanString = Cls.utils.SecondsToTime(0); m_bllc = new ALS.BLL.customactions(); if (m_bllc.Add(m_modc)) { //刷新列表,sort by timecount ShowCustomActions(_method); m_modc = null; UnEnableControl(); } } else { return; } } ALS.BLL.customactions bllcustom = new ALS.BLL.customactions(); ALS.Model.customactions modelcustom = bllcustom.GetModel(this._method, this.cmbAction.Text.Trim()); //CustomActions.BLL.actions bllaction = new CustomActions.BLL.actions(); //DataSet dsaction = bllaction.GetList("customID='"+ modelcustom.ID+"'"); //先查询该时间点是否有重复的 if (modelcustom != null) { MessageBox.Show("已存在相同的步骤名称,请重新设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { m_modc = new ALS.Model.customactions(); m_modc.timeString = Cls.utils.SecondsToTime(0); m_modc.actionName = this.cmbAction.Text.Trim(); m_modc.methodName = _method; m_modc.timeCount = 0; m_modc.timeSpan = timespan; m_modc.timeSpanString = Cls.utils.SecondsToTime(timespan); m_bllc = new ALS.BLL.customactions(); if (m_bllc.Add(m_modc)) { //刷新列表,sort by timecount ShowCustomActions(_method); m_modc = null; UnEnableControl(); } } }
private void dgCustomAction_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { UnEnableControl(); this.lblHourc.Enabled = true; this.lblMinc.Enabled = true; this.lblSecc.Enabled = true; this.tabActions.Enabled = true; this.btnUpdate.Enabled = true; m_customID = Convert.ToInt32(dgvCustomActions.Rows[e.RowIndex].Cells["ID"].Value.ToString()); //获取该步骤信息 m_modc = m_bllc.GetModel(m_customID); if (m_modc != null) { this.cmbAction.Text = m_modc.actionName; this.lbltsPump.Text = Cls.utils.SecondsToTime((int)m_modc.timeSpan); if (m_modc.timeSpan == 0) { //如果持续时间为0 则表示提示框 btnUpdate.Enabled = false; } else { btnUpdate.Enabled = true; } int hour = (int)m_modc.timeCount / 3600; int min = (int)(m_modc.timeCount % 3600) / 60; int sec = (int)m_modc.timeCount % 60; this.lblHour.Text = hour.ToString("00"); this.lblMin.Text = (min).ToString("00"); this.lblSec.Text = sec.ToString("00"); int hourc = (int)m_modc.timeSpan / 3600; int minc = (int)(m_modc.timeSpan % 3600) / 60; int secc = (int)(m_modc.timeSpan % 60); this.lblHourc.Text = hourc.ToString("00"); this.lblMinc.Text = minc.ToString("00"); this.lblSecc.Text = secc.ToString("00"); //读取提示图片 byte[] b = (byte[])m_modc.tipPic; if (b != null) { MemoryStream ms = new MemoryStream(b); Bitmap bmp = new Bitmap(ms); this.picTip.Image = bmp; ms.Close(); ms.Dispose(); } else { this.picTip.Image = null; } } //获取该时间点作列表 ShowActions(m_customID); } else { m_customID = -1; m_modc = null; this.tabActions.Enabled = false; } }