/// <summary> /// 数据操作 /// </summary> /// <param name="Mess">区别编辑还是新增还是删除</param> private bool OpreationDB(string Mess, CADS.Model.EconomicDevInfoList EconomicDevInfo) { try { string Error = ""; bool Result = false; if (Mess == "添加") { Result = EconomicDev.Add(EconomicDevInfo); } if (Mess == "编辑") { Result = EconomicDev.Update(EconomicDevInfo); } if (Mess == "删除") { Result = EconomicDev.Delete(EconomicDevInfo.ID); } if (Result == true) { MessageBox.Show("预案信息" + Mess + "成功"); return(true); } else { MessageBox.Show("预案信息" + Mess + "失败,请稍后再试!"); return(false); } } catch (Exception e) { MessageBox.Show("预案信息" + Mess + "失败:" + e.Message); return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CADS.Model.EconomicDevInfoList DataRowToModel(DataRow row) { CADS.Model.EconomicDevInfoList model = new CADS.Model.EconomicDevInfoList(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["Agriculture"] != null) { model.Agriculture = row["Agriculture"].ToString(); } if (row["Industry"] != null) { model.Industry = row["Industry"].ToString(); } if (row["Service"] != null) { model.Service = row["Service"].ToString(); } if (row["Mark"] != null) { model.Mark = row["Mark"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(CADS.Model.EconomicDevInfoList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update EconomicDevInfoList set "); if (model.Agriculture != null) { strSql.Append("Agriculture='" + model.Agriculture + "',"); } else { strSql.Append("Agriculture= null ,"); } if (model.Industry != null) { strSql.Append("Industry='" + model.Industry + "',"); } else { strSql.Append("Industry= null ,"); } if (model.Service != null) { strSql.Append("Service='" + model.Service + "',"); } else { strSql.Append("Service= null ,"); } if (model.Mark != null) { strSql.Append("Mark='" + model.Mark + "',"); } else { strSql.Append("Mark= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where ID=" + model.ID + ""); int rowsAffected = DbHelperOleDb.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }
public Form_EconomicDevAdd(string operType, CADS.Model.EconomicDevInfoList EconomicDevInfo) { InitializeComponent(); this.operType = operType; if (operType == "add") { Title_Label.Text = "战区经济发展状况添加"; } else { Title_Label.Text = "战区经济发展状况修改"; this.EconomicDevInfo = EconomicDevInfo; } }
private void btn_Delete_Click(object sender, EventArgs e) { if (DataView.SelectedRows.Count < 1) { MessageBox.Show("请选中一行数据!"); return; } if (MessageBox.Show("确定要删除该行数据?", null, MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } CADS.Model.EconomicDevInfoList EconomicDevInfo = new CADS.Model.EconomicDevInfoList(); EconomicDevInfo.ID = Convert.ToInt32(DataView.CurrentRow.Cells[0].Value); OpreationDB("删除", EconomicDevInfo); RefreshDataGridView(); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(CADS.Model.EconomicDevInfoList model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.Agriculture != null) { strSql1.Append("Agriculture,"); strSql2.Append("'" + model.Agriculture + "',"); } if (model.Industry != null) { strSql1.Append("Industry,"); strSql2.Append("'" + model.Industry + "',"); } if (model.Service != null) { strSql1.Append("Service,"); strSql2.Append("'" + model.Service + "',"); } if (model.Mark != null) { strSql1.Append("Mark,"); strSql2.Append("'" + model.Mark + "',"); } strSql.Append("insert into EconomicDevInfoList("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); int rows = DbHelperOleDb.ExecuteSql(strSql.ToString()); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CADS.Model.EconomicDevInfoList GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append(" ID,Agriculture,Industry,Service,Mark "); strSql.Append(" from EconomicDevInfoList "); strSql.Append(" where ID=" + ID + ""); CADS.Model.EconomicDevInfoList model = new CADS.Model.EconomicDevInfoList(); DataSet ds = DbHelperOleDb.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void btn_Edit_Click(object sender, EventArgs e) { if (DataView.SelectedRows.Count < 1) { MessageBox.Show("请选中一行数据!"); return; } CADS.Model.EconomicDevInfoList EconomicDevInfo = new CADS.Model.EconomicDevInfoList(); EconomicDevInfo.ID = Convert.ToInt32(DataView.CurrentRow.Cells[0].Value); EconomicDevInfo.Agriculture = DataView.CurrentRow.Cells[1].Value.ToString(); EconomicDevInfo.Industry = DataView.CurrentRow.Cells[2].Value.ToString(); EconomicDevInfo.Service = DataView.CurrentRow.Cells[3].Value.ToString(); Form_EconomicDevAdd addOrEdit = new Form_EconomicDevAdd("edit", EconomicDevInfo); addOrEdit.ShowDialog(); if (addOrEdit.DialogResult == DialogResult.OK) { OpreationDB("编辑", addOrEdit.EconomicDevInfo); RefreshDataGridView(); } }