private void btnExcel_Click(object sender, EventArgs e) { //获取Excel表头 List <string> headers; headers = EqTypeMgr.GetHeader("总表"); DataTable dt = ListToTable(headers); string filePath = string.Empty; FolderBrowserDialog BrowDialog = new FolderBrowserDialog(); BrowDialog.ShowNewFolderButton = true; BrowDialog.Description = "请选择模板保存位置"; if (BrowDialog.ShowDialog() == DialogResult.OK) { filePath = BrowDialog.SelectedPath;//这个就是点击选择文件夹的路径 filePath = filePath + "\\" + "资产表格模板" + ".xlsx"; if (ExcelMgr.ExportExcel(dt, filePath)) { untCommon.InfoMsg("导出成功"); } else { untCommon.InfoMsg("导出失败"); } } else { untCommon.InfoMsg("请选择资产类别"); } }
/// <summary> /// 初始化资产类型 /// </summary> private void InitType() { DataTable dt = EqTypeMgr.GetAllType(); if (dt != null) { cbxType.DataSource = dt; cbxType.DisplayMember = dt.Columns[1].ToString(); } }
private void btnTyp_Click(object sender, EventArgs e) { lstInfo.DataSource = null; lblMessge.Text = btnTyp.Text; DataTable dt = EqTypeMgr.GetAllType(); lstInfo.DataSource = dt; lstInfo.DisplayMember = dt.Columns[1].ToString();; lstInfo.ValueMember = dt.Columns[0].ToString(); }
/// <summary> /// 构造资产类比节点 /// </summary> /// <param name="parent">父节点</param> private void BuildType(TreeNode parent) { TreeNode Type = new TreeNode(); this.AddNode(Type, "资产类别", 7, parent); DataTable dt = EqTypeMgr.GetAllType(); if (dt != null) { for (int i = 0; i < dt.Rows.Count; i++) { TreeNode type = new TreeNode(); this.AddNode(type, dt.Rows[i][1].ToString(), 2, Type); } } }
/// <summary> /// 删除选中的项 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDel_Click(object sender, EventArgs e) { if (lstInfo.SelectedIndex == -1) { untCommon.InfoMsg("请选择所要删除的项。"); return; } switch (this.lblMessge.Text) { case "增长方式": //删除增长方式 if (untCommon.QuestionMsg("确定要删除该项吗")) { if (AddTypeMgr.Del(int.Parse(lstInfo.SelectedValue.ToString()))) { btnAddType_Click(null, null); } else { untCommon.InfoMsg("删除失败"); } } break; case "资产名称": //删除资产名称 if (untCommon.QuestionMsg("确定要删除该项吗")) { if (EqNameMgr.Del(int.Parse(lstInfo.SelectedValue.ToString()))) { btnName_Click(null, null); } else { untCommon.InfoMsg("删除失败"); } } break; case "保管地点": //删除保管地点 if (untCommon.QuestionMsg("确定要删除该项吗")) { if (KeepPlaceMgr.Del(int.Parse(lstInfo.SelectedValue.ToString()))) { btnKeepPlace_Click(null, null); } else { untCommon.InfoMsg("删除失败"); } } break; case "计量单位": //删除计量单位 if (untCommon.QuestionMsg("确定要删除该项吗")) { if (UnitMgr.Del(int.Parse(lstInfo.SelectedValue.ToString()))) { btnUnit_Click(null, null); } else { untCommon.InfoMsg("删除失败"); } } break; case "清理方式": //删除清理方式 if (untCommon.QuestionMsg("确定要删除该项吗")) { if (ClearTypeMgr.Del(int.Parse(lstInfo.SelectedValue.ToString()))) { btnClearType_Click(null, null); } else { untCommon.InfoMsg("删除失败"); } } break; case "资产类别": //添加增长方式 if (untCommon.QuestionMsg("确定要删除该项吗")) { if (EqTypeMgr.Del(int.Parse(lstInfo.SelectedValue.ToString()))) { btnTyp_Click(null, null); } else { untCommon.InfoMsg("删除失败"); } } break; } }
/// <summary> /// 保存添加项 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (this.txtInput.Text.Trim() == "") { untCommon.InfoMsg("不能添加空相,请填写所要添加的内容。"); return; } if (this.txtInput.Text == "请输入新加项的内容") { untCommon.InfoMsg("请输入合法的新项"); return; } switch (this.lblMessge.Text) { case "增长方式": //添加增长方式 if (AddTypeMgr.Add(this.txtInput.Text)) { btnAddType_Click(null, null); txtInput.Text = ""; txtInput.Focus(); this.btnDel.Enabled = true; } else { untCommon.InfoMsg("添加失败"); } break; case "资产名称": ////添加资产名称 if (EqNameMgr.AddName(this.txtInput.Text)) { btnName_Click(null, null); txtInput.Text = ""; txtInput.Focus(); this.btnDel.Enabled = true; } else { untCommon.InfoMsg("添加失败"); } break; case "保管地点": //添加保管地点 if (KeepPlaceMgr.AddPlace(this.txtInput.Text)) { btnKeepPlace_Click(null, null); txtInput.Text = ""; txtInput.Focus(); this.btnDel.Enabled = true; } else { untCommon.InfoMsg("添加失败"); } break; case "计量单位": //添加计量单位 if (UnitMgr.Add(this.txtInput.Text)) { btnUnit_Click(null, null); txtInput.Text = ""; txtInput.Focus(); this.btnDel.Enabled = true; } else { untCommon.InfoMsg("添加失败"); } break; case "清理方式": //添加清理方式 if (ClearTypeMgr.Add(this.txtInput.Text)) { btnClearType_Click(null, null); txtInput.Text = ""; txtInput.Focus(); this.btnDel.Enabled = true; } else { untCommon.InfoMsg("添加失败"); } break; case "资产类别": //添加增长方式 if (EqTypeMgr.AddType(this.txtInput.Text)) { btnTyp_Click(null, null); txtInput.Text = ""; txtInput.Focus(); this.btnDel.Enabled = true; } else { untCommon.InfoMsg("添加失败"); } break; } }