/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.port model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into port("); strSql.Append("mac,workid,manufacturer,portname,devicetype)"); strSql.Append(" values ("); strSql.Append("@mac,@workid,@manufacturer,@portname,@devicetype)"); MySqlParameter[] parameters = { new MySqlParameter("@mac", MySqlDbType.VarChar, 64), new MySqlParameter("@workid", MySqlDbType.VarChar, 64), new MySqlParameter("@manufacturer", MySqlDbType.VarChar, 255), new MySqlParameter("@portname", MySqlDbType.VarChar, 64), new MySqlParameter("@devicetype", MySqlDbType.Int32, 11) }; parameters[0].Value = model.mac; parameters[1].Value = model.workid; parameters[2].Value = model.manufacturer; parameters[3].Value = model.portname; parameters[4].Value = model.devicetype; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.port DataRowToModel(DataRow row) { Maticsoft.Model.port model = new Maticsoft.Model.port(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["mac"] != null) { model.mac = row["mac"].ToString(); } if (row["workid"] != null) { model.workid = row["workid"].ToString(); } if (row["manufacturer"] != null) { model.manufacturer = row["manufacturer"].ToString(); } if (row["portname"] != null) { model.portname = row["portname"].ToString(); } if (row["devicetype"] != null && row["devicetype"].ToString() != "") { model.devicetype = int.Parse(row["devicetype"].ToString()); } } return(model); }
private void importdev_st_FinishClick(object sender, CancelEventArgs e) { // MessageBox.Show("恭喜您设定完毕"); //MessageBox.Show(string.Format("您的机器id是 {0}", global.MachineID)); //MessageBox.Show(string.Format("您的设备昵称是 {0}", textBoxX2.Text)); string gz_name = textBoxX2.Text; // MessageBox.Show(string.Format("当前选择的串口是 == {0} == ", cur_work_portname)); Maticsoft.BLL.port tempport_bll = new Maticsoft.BLL.port(); string cur_macnum = global.MachineID; List <Maticsoft.Model.port> port_objs = tempport_bll.GetModelList(string.Format(" mac = '{0}' and portname= '{1}' ", cur_macnum, cur_work_portname)); // 先找是不是有 if (port_objs.Count > 0) { // 覆盖掉 Maticsoft.Model.port temp_port = port_objs[0]; temp_port.manufacturer = gz_name; temp_port.workid = textBoxX3.Text; temp_port.devicetype = type; tempport_bll.Update(temp_port); //// 如果存在的话 就先提醒一下。 用户点确认之后 覆盖以前的com //DialogResult ret = MessageBox.Show("发现已经存在com的记录", "是否使用这个名字", MessageBoxButtons.OKCancel); //if (ret == DialogResult.OK) //{ // // MessageBox.Show("以更新,工具已经可以使用"); //} } else { // 不存在就直接添加 Maticsoft.Model.port tmp_portobj = new Maticsoft.Model.port() { mac = cur_macnum, manufacturer = gz_name, portname = cur_work_portname, devicetype = type, workid = textBoxX3.Text }; tempport_bll.Add(tmp_portobj); } this.Close(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.port model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update port set "); strSql.Append("mac=@mac,"); strSql.Append("workid=@workid,"); strSql.Append("manufacturer=@manufacturer,"); strSql.Append("portname=@portname,"); strSql.Append("devicetype=@devicetype"); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@mac", MySqlDbType.VarChar, 64), new MySqlParameter("@workid", MySqlDbType.VarChar, 64), new MySqlParameter("@manufacturer", MySqlDbType.VarChar, 255), new MySqlParameter("@portname", MySqlDbType.VarChar, 64), new MySqlParameter("@devicetype", MySqlDbType.Int32, 11), new MySqlParameter("@id", MySqlDbType.Int32, 11) }; parameters[0].Value = model.mac; parameters[1].Value = model.workid; parameters[2].Value = model.manufacturer; parameters[3].Value = model.portname; parameters[4].Value = model.devicetype; parameters[5].Value = model.id; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.port GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,mac,workid,manufacturer,portname,devicetype from port "); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.Int32) }; parameters[0].Value = id; Maticsoft.Model.port model = new Maticsoft.Model.port(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }