/// <summary> /// 选择修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lvwUserList_DoubleClick(object sender, EventArgs e) { try { if (this.lvwUserList.SelectedRows.Count <= 0) { MessageBox.Show("请选择要修改的项!"); return; } if (this.lvwUserList.SelectedRows[0].Cells["PositionSMS_ID"].Value.ToString() == "") { MessageBox.Show("请选择要修改的项!"); return; } else { isUpdate = true; string sql = "select * from PositionSMS where PositionSMS_ID='" + this.lvwUserList.SelectedRows[0].Cells["PositionSMS_ID"].Value.ToString() + "'"; PositionSMS ps = PositionSMSDAL.GetSMS(sql); txtPositionSMS_Content.Text = ps.PositionSMS_Content.ToString(); txtPositionSMS_Count.Text = ps.PositionSMS_Remark.ToString(); combokPositionSMS_State.Text = ps.PositionSMS_State; chkPositionSMS_Position_Id.SelectedIndex = int.Parse(ps.PositionSMS_Position_ID.ToString()) - 1; } btnUpdate.Enabled = true; btnDelete.Enabled = true; btnAdd.Enabled = false; } catch { CommonalityEntity.WriteTextLog("LEDSetForm lvwUserList_DoubleClick()" + "");//记录异常日志 } }
/// <summary> /// 添加 /// </summary> /// <param name="pLED">实体</param> /// <returns>返回执行结果 true or false</returns> public static bool InsertPositionSMS(PositionSMS pSMS) { bool rbool = false; using (DCCarManagementDataContext dc = new DCCarManagementDataContext()) { try { rbool = LinQBaseDao.InsertOne <PositionSMS>(dc, pSMS); } catch { rbool = false; } finally { dc.Connection.Close(); } } return(rbool); }
/// <summary> /// 获取LED设置 /// </summary> /// <param name="sql"></param> /// <returns></returns> public static PositionSMS GetSMS(string sql) { DataSet dataset = LinQBaseDao.Query(sql); PositionSMS ps = new PositionSMS(); foreach (DataRow dr in dataset.Tables[0].Rows) { ps.PositionSMS_Content = dr["PositionSMS_Content"].ToString(); ps.PositionSMS_Count = int.Parse(dr["PositionSMS_Count"].ToString()); ps.PositionSMS_ID = int.Parse(dr["PositionSMS_ID"].ToString()); ps.PositionSMS_Operate = dr["PositionSMS_Operate"].ToString(); ps.PositionSMS_Position_ID = int.Parse(dr["PositionSMS_Position_ID"].ToString()); ps.PositionSMS_Remark = dr["PositionSMS_Remark"].ToString(); ps.PositionSMS_State = dr["PositionSMS_State"].ToString(); ps.PositionSMS_Time = Convert.ToDateTime(dr["PositionSMS_Time"].ToString()); //ps.PositionSMS_Type = int.Parse(dr["PositionSMS_Type"].ToString()); } return(ps); }
/// <summary> /// 保存当前设置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtPositionSMS_Count.Text.Trim())) { MessageBox.Show("发送间隔不能为空!"); return; } int scount = Convert.ToInt32(txtPositionSMS_Count.Text.Trim()); //得到输入的数据 PositionSMS ps = new PositionSMS(); ps.PositionSMS_Content = txtPositionSMS_Content.Text.Trim(); ps.PositionSMS_Count = scount; ps.PositionSMS_Operate = CommonalityEntity.USERNAME; ps.PositionSMS_Position_ID = int.Parse(chkPositionSMS_Position_Id.SelectedValue.ToString()); //ps.PositionSMS_Type = txtPositionSMS_Type.Text.Trim(); ps.PositionSMS_Time = CommonalityEntity.GetServersTime(); ps.PositionSMS_State = combokPositionSMS_State.Text.ToString(); if (combokPositionSMS_State.Text.Trim() == "启动") { if (ChkPositionSMSState()) { DialogResult dlgResult = MessageBox.Show("已经存在启动状态的设置,是否替换?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dlgResult == DialogResult.OK) { //修改条件 Expression <Func <PositionSMS, bool> > fun = n => n.PositionSMS_State == "启动" && n.PositionSMS_Position_ID == int.Parse(chkPositionSMS_Position_Id.SelectedValue.ToString()); //需要修改的内容 Action <PositionSMS> action = p => { p.PositionSMS_State = "暂停"; }; //执行更新 PositionSMSDAL.UpdatePositionSMS(fun, action); PositionSMSDAL.InsertPositionSMS(ps); } else { ps.PositionSMS_State = "暂停"; PositionSMSDAL.InsertPositionSMS(ps); } } else { PositionSMSDAL.InsertPositionSMS(ps); } } else { PositionSMSDAL.InsertPositionSMS(ps); } DataTable dt = LinQBaseDao.Query("select PositionSMS_ID,PositionSMS_State from PositionSMS order by PositionSMS_ID desc ").Tables[0]; string positionsms_id = dt.Rows[0][0].ToString(); string positionsms_state = dt.Rows[0][1].ToString(); if (positionsms_state == "启动") { CommonalityEntity.WriteLogData("新增", "新增并启动编号为: " + positionsms_id + "的短信提示信息", CommonalityEntity.USERNAME);//添加操作日志 } else { CommonalityEntity.WriteLogData("新增", "新增编号为: " + positionsms_id + "的短信提示信息", CommonalityEntity.USERNAME);//添加操作日志 } } catch { CommonalityEntity.WriteTextLog("SMSSetForm btnAdd_Click()" + ""); } finally { GetGriddataviewLoad(""); Cler(); } }