public bool Insert(MODELwaterMeterSize MODELwaterMeterSize) { StringBuilder str = new StringBuilder(); str.Append("INSERT INTO dbo.waterMeterSize(waterMeterSizeId,waterMeterSizeValue,waterLossComputeType,checkPeriod,waterLossValue,MEMO) "); str.Append("VALUES(@waterMeterSizeId,@waterMeterSizeValue,@waterLossComputeType,@checkPeriod,@waterLossValue,@MEMO)"); SqlParameter[] para = { new SqlParameter("@waterMeterSizeId", SqlDbType.VarChar, 30), new SqlParameter("@waterMeterSizeValue", SqlDbType.VarChar, 50), new SqlParameter("@waterLossComputeType", SqlDbType.VarChar, 10), new SqlParameter("@checkPeriod", SqlDbType.Int), new SqlParameter("@waterLossValue", SqlDbType.Float), new SqlParameter("@MEMO", SqlDbType.VarChar, 200) }; para[0].Value = MODELwaterMeterSize.waterMeterSizeId; para[1].Value = MODELwaterMeterSize.waterMeterSizeValue; para[2].Value = MODELwaterMeterSize.waterLossComputeType; para[3].Value = MODELwaterMeterSize.checkPeriod; para[4].Value = MODELwaterMeterSize.waterLossValue; para[5].Value = MODELwaterMeterSize.MEMO; if (DBUtility.DbHelperSQL.ExecuteSql(str.ToString(), para) > 0) { return(true); } else { return(false); } }
public bool Update(MODELwaterMeterSize MODELwaterMeterSize) { StringBuilder str = new StringBuilder(); str.Append("UPDATE dbo.waterMeterSize SET waterMeterSizeValue=@waterMeterSizeValue,waterLossComputeType=@waterLossComputeType,checkPeriod=@checkPeriod,waterLossValue=@waterLossValue,MEMO=@MEMO "); str.Append("WHERE waterMeterSizeId=@waterMeterSizeId"); SqlParameter[] para = { new SqlParameter("@waterMeterSizeValue", SqlDbType.VarChar, 50), new SqlParameter("@waterLossComputeType", SqlDbType.VarChar, 10), new SqlParameter("@checkPeriod", SqlDbType.Int), new SqlParameter("@waterLossValue", SqlDbType.Float), new SqlParameter("@MEMO", SqlDbType.VarChar, 200), new SqlParameter("@waterMeterSizeId", SqlDbType.VarChar, 30) }; para[0].Value = MODELwaterMeterSize.waterMeterSizeValue; para[1].Value = MODELwaterMeterSize.waterLossComputeType; para[2].Value = MODELwaterMeterSize.checkPeriod; para[3].Value = MODELwaterMeterSize.waterLossValue; para[4].Value = MODELwaterMeterSize.MEMO; para[5].Value = MODELwaterMeterSize.waterMeterSizeId; if (DBUtility.DbHelperSQL.ExecuteSql(str.ToString(), para) > 0) { return(true); } else { return(false); } }
private void toolSave_Click(object sender, EventArgs e) { if (txtName.Text.Trim() == "") { mes.Show("类别名称不能为空!"); txtName.Focus(); return; } if (rbFixed.Checked) { if (txtFixed.Text.Trim() == "") { txtFixed.Text = "0"; } else { if (!Information.IsNumeric(txtFixed.Text.Trim())) { mes.Show("固定水量只能为整数!"); txtFixed.Focus(); return; } } } if (rbPercent.Checked) { if (txtPercent.Text.Trim() == "") { txtPercent.Text = "0"; } else { if (!Information.IsNumeric(txtPercent.Text.Trim())) { mes.Show("按比例只能为数字!"); txtPercent.Focus(); return; } } } if (txtCheckPeriod.Text.Trim() == "") { txtCheckPeriod.Text = "0"; } else { if (!Information.IsNumeric(txtCheckPeriod.Text.Trim())) { mes.Show("鉴定周期只能为整数!"); txtCheckPeriod.Focus(); return; } } MODELwaterMeterSize MODELwaterMeterSize = new MODELwaterMeterSize(); MODELwaterMeterSize.waterMeterSizeValue = txtName.Text; MODELwaterMeterSize.checkPeriod = Convert.ToInt32(txtCheckPeriod.Text); if (rbFixed.Checked) { MODELwaterMeterSize.waterLossComputeType = "0"; MODELwaterMeterSize.waterLossValue = Convert.ToInt32(txtFixed.Text); } else { MODELwaterMeterSize.waterLossComputeType = "1"; MODELwaterMeterSize.waterLossValue = Convert.ToDecimal(txtPercent.Text); } MODELwaterMeterSize.MEMO = txtMemo.Text; if (isAdd) { MODELwaterMeterSize.waterMeterSizeId = GETTABLEID.GetTableID("", "WATERMETERSIZE"); if (BLLwaterMeterSize.Insert(MODELwaterMeterSize)) { Query(); } else { mes.Show("添加失败,请重新点击保存按钮!"); return; } } else { MODELwaterMeterSize.waterMeterSizeId = txtID.Text; if (BLLwaterMeterSize.Update(MODELwaterMeterSize)) { Query(); dgList.ClearSelection(); for (int i = 0; i < dgList.Rows.Count; i++) { if (dgList.Rows[i].Cells["waterMeterSizeId"].Value != null && dgList.CurrentRow.Cells["waterMeterSizeId"].Value != DBNull.Value) { string strID = dgList.Rows[i].Cells["waterMeterSizeId"].Value.ToString(); if (MODELwaterMeterSize.waterMeterSizeId == strID) { dgList.CurrentCell = dgList.Rows[i].Cells["waterMeterSizeValue"]; dgList_SelectionChanged(null, null); } } } } else { mes.Show("修改失败,请重新点击保存按钮!"); return; } } dgList.Enabled = true; toolDel.Enabled = true; toolAdd.Text = "添加"; isAdd = false; }