📄 dictmanageform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using CallCenter.BusinessInterfaces.BaseForms.Models;
using CallCenter.BusinessInterfaces;
using CallCenter.BusinessLayer;
using CallCenter.Modules;
namespace CallCenter.BusinessInterfaces.BaseForms {
/// <summary>
/// DictManageForm 的摘要说明。
/// </summary>
public class DictManageForm : System.Windows.Forms.UserControl {
private System.Windows.Forms.Button btnNew;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.ComboBox cmbDicTable;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tbContent;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox tbId;
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private IList DictTablesList;
private IList m_currentList;
private string opState="update";
private int m_Id=0;
private string m_Content = string.Empty;
private int[] DisplayCol={0,1};
private string[] DisplayProp = {"id","content"};
private OtherBLL m_OtherBLL = new OtherBLL();
private OtherInfo m_OtherInfo = new OtherInfo();
private OtherInfoColumn m_OtherInfoColumn = new OtherInfoColumn();
private System.Windows.Forms.Panel LVPanel;
private System.Windows.Forms.Button btnCancel;
private ListViewHelper m_ListView = new ListViewHelper();
#region properties
private int Id{
get{
this.m_Id = int.Parse(this.tbId.Text.Trim());
return this.m_Id;
}
set{
this.m_Id = value;
}
}
private string Content{
get{
this.m_Content = this.tbContent.Text.Trim();
return this.m_Content;
}
set{
this.m_Content = value;
}
}
#endregion
#region 构造
public DictManageForm() {
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
InitiaCmbDictTable();
InitiaListViewHead();
RefreshListView();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing ) {
if( disposing ) {
if(components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent() {
this.btnNew = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.cmbDicTable = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.LVPanel = new System.Windows.Forms.Panel();
this.tbContent = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.tbId = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnNew
//
this.btnNew.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnNew.Location = new System.Drawing.Point(544, 216);
this.btnNew.Name = "btnNew";
this.btnNew.Size = new System.Drawing.Size(75, 24);
this.btnNew.TabIndex = 21;
this.btnNew.Text = "新建";
this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
//
// btnSave
//
this.btnSave.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSave.Location = new System.Drawing.Point(416, 216);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(75, 24);
this.btnSave.TabIndex = 18;
this.btnSave.Text = "保存";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// cmbDicTable
//
this.cmbDicTable.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDicTable.Location = new System.Drawing.Point(504, 24);
this.cmbDicTable.Name = "cmbDicTable";
this.cmbDicTable.Size = new System.Drawing.Size(121, 20);
this.cmbDicTable.TabIndex = 17;
//
// label3
//
this.label3.Location = new System.Drawing.Point(384, 24);
this.label3.Name = "label3";
this.label3.TabIndex = 16;
this.label3.Text = "选择字典表";
//
// LVPanel
//
this.LVPanel.AutoScroll = true;
this.LVPanel.Dock = System.Windows.Forms.DockStyle.Left;
this.LVPanel.Location = new System.Drawing.Point(0, 0);
this.LVPanel.Name = "LVPanel";
this.LVPanel.Size = new System.Drawing.Size(350, 280);
this.LVPanel.TabIndex = 15;
//
// tbContent
//
this.tbContent.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tbContent.Location = new System.Drawing.Point(504, 88);
this.tbContent.Name = "tbContent";
this.tbContent.Size = new System.Drawing.Size(120, 21);
this.tbContent.TabIndex = 14;
this.tbContent.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(384, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(112, 23);
this.label2.TabIndex = 13;
this.label2.Text = "内容";
//
// tbId
//
this.tbId.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tbId.Location = new System.Drawing.Point(504, 56);
this.tbId.Name = "tbId";
this.tbId.Size = new System.Drawing.Size(120, 21);
this.tbId.TabIndex = 12;
this.tbId.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(384, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 23);
this.label1.TabIndex = 11;
this.label1.Text = "序号";
//
// btnCancel
//
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.Location = new System.Drawing.Point(544, 216);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 24);
this.btnCancel.TabIndex = 22;
this.btnCancel.Text = "取消";
this.btnCancel.Visible = false;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// DictManageForm
//
this.AutoScroll = true;
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnNew);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.cmbDicTable);
this.Controls.Add(this.label3);
this.Controls.Add(this.LVPanel);
this.Controls.Add(this.tbContent);
this.Controls.Add(this.tbId);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "DictManageForm";
this.Size = new System.Drawing.Size(672, 280);
this.ResumeLayout(false);
}
#endregion
#region method
/// <summary>
/// 初始化字典下拉列表
/// </summary>
private void InitiaCmbDictTable(){
try{
DictTablesList = this.m_OtherBLL.getDictironary();
if(DictTablesList.Count>0){
this.cmbDicTable.DataSource = DictTablesList;
this.cmbDicTable.ValueMember = "enname";
this.cmbDicTable.DisplayMember = "chname";
this.cmbDicTable.SelectedValue = "SPType";
this.cmbDicTable.SelectedValueChanged+=new EventHandler(cmbDicTable_ValueMemberChanged);
}
}catch(Exception ex){
}
}
private void InitiaListViewHead(){
m_ListView.InitLV_UserDefined(m_OtherInfoColumn,DisplayCol);
m_ListView.Dock = DockStyle.Fill;
m_ListView.Columns[0].Width = 40;
m_ListView.Columns[0].TextAlign = HorizontalAlignment.Center;
m_ListView.Columns[1].Width = 300;
this.LVPanel.Controls.Add(m_ListView);
this.m_ListView.SelectedIndexChanged+=new EventHandler(m_ListView_SelectedIndexChanged);
}
private void RefreshListView(){
if(this.cmbDicTable.SelectedValue is string){
string tableName = (string)this.cmbDicTable.SelectedValue;
this.m_currentList = GetSelectedDictTableList(this.m_OtherBLL,tableName);
if(m_currentList!=null){
m_ListView.Refresh_UserDefine(m_currentList,m_OtherInfo,DisplayProp);
}
}
}
private void Save(object o,string tableName){
try{
if(!ValidateData()){
return ;
}
string methodName = opState+tableName;
DynamicSave(o,methodName);
MessageBox.Show("保存成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
UpdateStateData();
RefreshListView();
}catch(Exception ex){
MessageBox.Show("保存失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
/// <summary>
/// 动态保存,根据下拉表里的表名,去调相应的方法
/// </summary>
/// <param name="o">调用方法的类对象</param>
/// <param name="methodName">方法名</param>
private void DynamicSave(object o,string methodName){
System.Reflection.MethodInfo method;
method = o.GetType().GetMethod(methodName);
if(method!=null){
object[] parameters = {Id,Content};
method.Invoke(o,parameters);
}
}
private IList GetSelectedDictTableList(object o,string tableName){
System.Reflection.MethodInfo method;
string methodName = "get"+tableName;
method = o.GetType().GetMethod(methodName);
IList list;
try{
if(method!=null){
list = (IList)method.Invoke(o,null);
return list;
}
return null;
}catch(Exception ex){
return null;
}
}
private bool ValidateData(){
try{
this.m_Id = int.Parse(this.tbId.Text.Trim());
}catch(Exception ex){
MessageBox.Show("序号只能是数字!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return false;
}
if(this.tbContent.Text.Trim().Equals("")){
MessageBox.Show("内容不能为空!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return false;
}
if(this.tbContent.Text.Trim().Length>30){
MessageBox.Show("长度不能大于30个字符!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return false;
}
return true;
}
//
private void NewStateData(){
this.opState = "add";
this.tbId.Text = "";
this.tbContent.Text = "";
this.btnNew.Visible = false;
this.btnCancel.Visible = true;
}
private void UpdateStateData(){
this.opState = "update";
this.btnNew.Visible = true;
this.btnCancel.Visible = false;
}
#endregion
#region events
private void cmbDicTable_ValueMemberChanged(object sender, EventArgs e) {
RefreshListView();
}
private void m_ListView_SelectedIndexChanged(object sender, EventArgs e) {
if(m_ListView.SelectedIndices.Count>0){
int itemIndex = m_ListView.SelectedIndices[0];
this.tbId.Text = m_ListView.Items[itemIndex].SubItems[0].Text;
this.tbContent.Text = m_ListView.Items[itemIndex].SubItems[1].Text;
try{
m_Id = int.Parse(this.tbId.Text.Trim());
m_Content = this.tbContent.Text.Trim();
}catch(Exception ex){
MessageBox.Show(ex.Message,"警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
}
private void btnNew_Click(object sender, System.EventArgs e) {
NewStateData();
}
private void btnSave_Click(object sender, System.EventArgs e) {
Save(this.m_OtherBLL,(string)this.cmbDicTable.SelectedValue);
}
private void btnRefresh_Click(object sender, System.EventArgs e) {
RefreshListView();
}
private void btnCancel_Click(object sender, System.EventArgs e) {
UpdateStateData();
this.tbId.Text =this.m_Id.ToString();
this.tbContent.Text =this.m_Content;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -