/// <summary> /// 修改计量单位 /// </summary> /// <param name="units"></param> /// <returns></returns> public bool UpdateUnits(UnitsItems units) { string sql = "Update table_units set UnitName=@UnitName,IsEnable=@IsEnable where ObjectID=@ObjectID"; SQLiteParameter[] sqlparamter = new SQLiteParameter[] { new SQLiteParameter("@ObjectID", units.ObjectID), new SQLiteParameter("@UnitName", units.UnitsName), new SQLiteParameter("@IsEnable", units.IsEnable), }; return(SqlHelper.ExecuteNonQuery(sql, sqlparamter) == 1); }
/// <summary> /// 新增计量单位 /// </summary> /// <param name="units"></param> /// <returns></returns> public bool InsertUnits(UnitsItems units) { string sql = "INSERT into table_units (ObjectID,UnitName,IsEnable,IsDelete) VALUES(@ObjectID,@UnitName,@IsEnable,@IsDelete)"; SQLiteParameter[] sqlparamter = new SQLiteParameter[] { new SQLiteParameter("@ObjectID", units.ObjectID), new SQLiteParameter("@UnitName", units.UnitsName), new SQLiteParameter("@IsEnable", units.IsEnable), new SQLiteParameter("@IsDelete", "N") }; return(SqlHelper.ExecuteNonQuery(sql, sqlparamter) == 1); }
private void Btn_Save_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(Txt_UnitName.Text)) { MessageBox.Show("请输入计量单位名称"); return; } try { var item = new UnitsItems() { ObjectID = Txt_UnitID.Text, UnitsName = Txt_UnitName.Text, IsEnable = Rbtn_Yes.Checked ? "Y" : "N" }; var result = IsEdit ? new UnitsQuery().UpdateUnits(item) : new UnitsQuery().InsertUnits(item); if (result) { MessageBox.Show("保存成功"); if (IsEdit) { this.Close(); } else { var unitId = Guid.NewGuid().ToString(); while (new UnitsQuery().GetUnit(unitId) != null) { unitId = Guid.NewGuid().ToString(); } Txt_UnitID.Text = unitId; Txt_UnitName.Text = String.Empty; } } } catch (Exception exp) { MessageBox.Show("保存失败," + exp.Message); } }