/// <summary> /// 添加一个协议,自动判断是否存在Id,若存在Id则不会添加 /// </summary> /// <param name="con"></param> /// <returns></returns> public static string addContract(DataSet dataSet, Contract con) { DataRowCollection rows = dataSet.Tables[0].Rows; foreach (DataRow r in rows) { if (r["协议编号"].ToString() == con.proId) { return("已包含协议编号为:" + con.proId + " 的协议。不能再添加!"); } } DataRow row = dataSet.Tables[0].NewRow(); row = ContractUtil.getRowFromContract(row, con); dataSet.Tables[0].Rows.Add(row); return("添加协议:" + con.proId + " " + con.proName + " 成功!"); }
/// <summary> /// 弹出对话框,添加新合同 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addNewContractBtn_Click(object sender, EventArgs e) { ContractEditForm cef = new ContractEditForm("add", "添加新合同", "确定添加", null); cef.ShowDialog(); if (cef.IsCanel) { cef.Dispose(); return; } Contract con = cef.Contract; if (con != null) { if (con.fileName != "") { FileInfo f = new FileInfo(con.fileName); if (new FileInfo(Contract.relativePath + f.Name).Exists) { statusLab.Text = "已经存在文件名为:" + Contract.relativePath + f.Name + " 的文件,请更改文件名再添加"; MessageBox.Show(statusLab.Text); return; } f.CopyTo(Contract.relativePath + f.Name); con.fileName = f.Name; } DataRow row = showDataSet.Tables[0].NewRow(); row = ContractUtil.getRowFromContract(row, con); showDataSet.Tables[0].Rows.Add(row); //自动保存数据 saveToolStripMenuItem_Click(sender, e); } }
/// <summary> /// 搜索按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void searchStripBtn_Click(object sender, EventArgs e) { string clas = searchCombo.Text; string content = searchTxt.Text; if (clas == "" || content == "") { MessageBox.Show("搜索类型和搜索内容不能为空,请输入完整后再搜索!"); return; } clas = clas.Replace("按", "").Replace("查找", ""); List <DataRow> resRows = ContractUtil.findContract(showDataSet, clas, content); searchDataSet.Tables[0].Rows.Clear(); foreach (DataRow row in resRows) { Contract con = ContractUtil.getContractFromRow(row); DataRow nrow = searchDataSet.Tables[0].NewRow(); nrow = ContractUtil.getRowFromContract(nrow, con); searchDataSet.Tables[0].Rows.Add(nrow); } statusLab.Text = ContractUtil.statusLab; }