private void btn_DutyEdit_Click(object sender, EventArgs e) { if (dgv_LawsFileInfo.SelectedRows.Count < 1) { MessageBox.Show("请选中一行数据!"); return; } CADS.Model.LawsFileInfo lawsFileInfo = new CADS.Model.LawsFileInfo(); lawsFileInfo.ID = Convert.ToInt32(dgv_LawsFileInfo.CurrentRow.Cells[0].Value); lawsFileInfo.FileName = dgv_LawsFileInfo.CurrentRow.Cells[1].Value.ToString(); lawsFileInfo.FileType = dgv_LawsFileInfo.CurrentRow.Cells[2].Value.ToString(); lawsFileInfo.IssueTime = dgv_LawsFileInfo.CurrentRow.Cells[3].Value.ToString(); lawsFileInfo.IssueOrganization = dgv_LawsFileInfo.CurrentRow.Cells[4].Value.ToString(); lawsFileInfo.IssueVersion = dgv_LawsFileInfo.CurrentRow.Cells[5].Value.ToString(); lawsFileInfo.FilePath = dgv_LawsFileInfo.CurrentRow.Cells[6].Value.ToString(); lawsFileInfo.Descrpition = dgv_LawsFileInfo.CurrentRow.Cells[7].Value.ToString(); Form_LawFileAdd addOrEdit = new Form_LawFileAdd("edit", lawsFileInfo); addOrEdit.ShowDialog(); if (addOrEdit.DialogResult == DialogResult.OK) { OpreationDB("编辑", addOrEdit.lawsFileInfo); RefreshDataGridView(); } }
/// <summary> /// 数据操作 /// </summary> /// <param name="Mess">区别编辑还是新增还是删除</param> private bool OpreationDB(string Mess, CADS.Model.LawsFileInfo lawsFileInfo) { try { string Error = ""; bool Result = false; if (Mess == "添加") { Result = lawsFile.Add(lawsFileInfo); } if (Mess == "编辑") { Result = lawsFile.Update(lawsFileInfo); } if (Mess == "删除") { Result = lawsFile.Delete(lawsFileInfo.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); } }
public Form_LawFileAdd(string operType, CADS.Model.LawsFileInfo lawsFileInfo) { InitializeComponent(); if (operType == "add") { Title_Label.Text = "文件添加"; } else { Title_Label.Text = "文件编辑"; } this.lawsFileInfo = lawsFileInfo; this.operType = operType; lawsFile = new CADS.BLL.LawsFileInfo(); }
/// <summary> /// 得到一个对象实体 /// </summary> public CADS.Model.LawsFileInfo DataRowToModel(DataRow row) { CADS.Model.LawsFileInfo model = new CADS.Model.LawsFileInfo(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["FileName"] != null) { model.FileName = row["FileName"].ToString(); } if (row["FileType"] != null) { model.FileType = row["FileType"].ToString(); } if (row["IssueTime"] != null) { model.IssueTime = row["IssueTime"].ToString(); } if (row["IssueOrganization"] != null) { model.IssueOrganization = row["IssueOrganization"].ToString(); } if (row["IssueVersion"] != null) { model.IssueVersion = row["IssueVersion"].ToString(); } if (row["FilePath"] != null) { model.FilePath = row["FilePath"].ToString(); } if (row["Descrpition"] != null) { model.Descrpition = row["Descrpition"].ToString(); } if (row["Mark"] != null) { model.Mark = row["Mark"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public CADS.Model.LawsFileInfo GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append(" ID,FileName,FileType,IssueTime,IssueOrganization,IssueVersion,FilePath,Descrpition,Mark "); strSql.Append(" from LawsFileInfo "); strSql.Append(" where ID=" + ID + ""); CADS.Model.LawsFileInfo model = new CADS.Model.LawsFileInfo(); 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_DeleteFile_Click(object sender, EventArgs e) { if (dgv_LawsFileInfo.SelectedRows.Count < 1) { MessageBox.Show("请选中一行数据!"); return; } if (MessageBox.Show("确定要删除该行数据?", null, MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } CADS.Model.LawsFileInfo lawsFileInfo = new CADS.Model.LawsFileInfo(); lawsFileInfo.ID = Convert.ToInt32(dgv_LawsFileInfo.CurrentRow.Cells[0].Value); lawsFileInfo.FileName = dgv_LawsFileInfo.CurrentRow.Cells[1].Value.ToString(); lawsFileInfo.FileType = dgv_LawsFileInfo.CurrentRow.Cells[2].Value.ToString(); lawsFileInfo.IssueTime = dgv_LawsFileInfo.CurrentRow.Cells[3].Value.ToString(); lawsFileInfo.IssueOrganization = dgv_LawsFileInfo.CurrentRow.Cells[4].Value.ToString(); lawsFileInfo.IssueVersion = dgv_LawsFileInfo.CurrentRow.Cells[5].Value.ToString(); lawsFileInfo.FilePath = dgv_LawsFileInfo.CurrentRow.Cells[6].Value.ToString(); lawsFileInfo.Descrpition = dgv_LawsFileInfo.CurrentRow.Cells[7].Value.ToString(); OpreationDB("删除", lawsFileInfo); RefreshDataGridView(); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(CADS.Model.LawsFileInfo model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.FileName != null) { strSql1.Append("FileName,"); strSql2.Append("'" + model.FileName + "',"); } if (model.FileType != null) { strSql1.Append("FileType,"); strSql2.Append("'" + model.FileType + "',"); } if (model.IssueTime != null) { strSql1.Append("IssueTime,"); strSql2.Append("'" + model.IssueTime + "',"); } if (model.IssueOrganization != null) { strSql1.Append("IssueOrganization,"); strSql2.Append("'" + model.IssueOrganization + "',"); } if (model.IssueVersion != null) { strSql1.Append("IssueVersion,"); strSql2.Append("'" + model.IssueVersion + "',"); } if (model.FilePath != null) { strSql1.Append("FilePath,"); strSql2.Append("'" + model.FilePath + "',"); } if (model.Descrpition != null) { strSql1.Append("Descrpition,"); strSql2.Append("'" + model.Descrpition + "',"); } if (model.Mark != null) { strSql1.Append("Mark,"); strSql2.Append("'" + model.Mark + "',"); } strSql.Append("insert into LawsFileInfo("); 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 bool Update(CADS.Model.LawsFileInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update LawsFileInfo set "); if (model.FileName != null) { strSql.Append("FileName='" + model.FileName + "',"); } else { strSql.Append("FileName= null ,"); } if (model.FileType != null) { strSql.Append("FileType='" + model.FileType + "',"); } else { strSql.Append("FileType= null ,"); } if (model.IssueTime != null) { strSql.Append("IssueTime='" + model.IssueTime + "',"); } else { strSql.Append("IssueTime= null ,"); } if (model.IssueOrganization != null) { strSql.Append("IssueOrganization='" + model.IssueOrganization + "',"); } else { strSql.Append("IssueOrganization= null ,"); } if (model.IssueVersion != null) { strSql.Append("IssueVersion='" + model.IssueVersion + "',"); } else { strSql.Append("IssueVersion= null ,"); } if (model.FilePath != null) { strSql.Append("FilePath='" + model.FilePath + "',"); } else { strSql.Append("FilePath= null ,"); } if (model.Descrpition != null) { strSql.Append("Descrpition='" + model.Descrpition + "',"); } else { strSql.Append("Descrpition= 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); } }