📄 dictmanageform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using CallCenter.Modules;
using CallCenter.BusinessLayer;
using CallCenter.BusinessInterfaces;
using CallCenter.BusinessInterfaces.BaseForms.Models;
using CallCenter.BusinessInterfaces.MainForms;
namespace CallCenter.BusinessInterfaces.BaseForms {
/// <summary>
/// DictManageForm 字典管理模块
/// author:yanqingxi
/// </summary>
public class DictManageForm : System.Windows.Forms.UserControl {
#region fields
private System.Windows.Forms.ComboBox cmbDicTable;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private int m_Id=0;
private IList m_currentList;
private IList DictTablesList;
private int[] DisplayCol={0,1};
private string opState="update";
private string m_Content = string.Empty;
private string[] DisplayProp = {"id","content"};
private OtherBLL m_OtherBLL = new OtherBLL();
private OtherInfo m_OtherInfo = new OtherInfo();
private OtherInfoColumn m_OtherInfoColumn = new OtherInfoColumn();
private DevExpress.XtraEditors.PanelControl LVPanel;
private DevExpress.XtraEditors.PanelControl panelControl1;
private DevExpress.XtraEditors.TextEdit tbId;
private DevExpress.XtraEditors.TextEdit tbContent;
private DevExpress.XtraEditors.SimpleButton btnSave;
private DevExpress.XtraEditors.SimpleButton btnCancel;
private DevExpress.XtraEditors.SimpleButton btnNew;
private ListViewHelper m_ListView = new ListViewHelper();
#endregion
#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() {
InitializeComponent();
InitiaCmbDictTable();
InitiaListView();
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.cmbDicTable = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.LVPanel = new DevExpress.XtraEditors.PanelControl();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.panelControl1 = new DevExpress.XtraEditors.PanelControl();
this.tbId = new DevExpress.XtraEditors.TextEdit();
this.tbContent = new DevExpress.XtraEditors.TextEdit();
this.btnSave = new DevExpress.XtraEditors.SimpleButton();
this.btnCancel = new DevExpress.XtraEditors.SimpleButton();
this.btnNew = new DevExpress.XtraEditors.SimpleButton();
((System.ComponentModel.ISupportInitialize)(this.LVPanel)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.panelControl1)).BeginInit();
this.panelControl1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.tbId.Properties)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tbContent.Properties)).BeginInit();
this.SuspendLayout();
//
// cmbDicTable
//
this.cmbDicTable.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbDicTable.Location = new System.Drawing.Point(128, 16);
this.cmbDicTable.Name = "cmbDicTable";
this.cmbDicTable.Size = new System.Drawing.Size(224, 20);
this.cmbDicTable.TabIndex = 17;
//
// label3
//
this.label3.Location = new System.Drawing.Point(56, 16);
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(280, 280);
this.LVPanel.TabIndex = 15;
//
// label2
//
this.label2.Location = new System.Drawing.Point(56, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(112, 23);
this.label2.TabIndex = 13;
this.label2.Text = "内容";
//
// label1
//
this.label1.Location = new System.Drawing.Point(56, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 23);
this.label1.TabIndex = 11;
this.label1.Text = "序号";
//
// panelControl1
//
this.panelControl1.Controls.Add(this.btnNew);
this.panelControl1.Controls.Add(this.btnCancel);
this.panelControl1.Controls.Add(this.btnSave);
this.panelControl1.Controls.Add(this.tbContent);
this.panelControl1.Controls.Add(this.tbId);
this.panelControl1.Controls.Add(this.cmbDicTable);
this.panelControl1.Controls.Add(this.label3);
this.panelControl1.Controls.Add(this.label2);
this.panelControl1.Controls.Add(this.label1);
this.panelControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelControl1.Location = new System.Drawing.Point(280, 0);
this.panelControl1.Name = "panelControl1";
this.panelControl1.Size = new System.Drawing.Size(392, 280);
this.panelControl1.TabIndex = 63;
this.panelControl1.Text = "panelControl1";
//
// tbId
//
this.tbId.EditValue = "";
this.tbId.Location = new System.Drawing.Point(128, 48);
this.tbId.Name = "tbId";
//
// tbId.Properties
//
this.tbId.Properties.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
this.tbId.Size = new System.Drawing.Size(224, 21);
this.tbId.TabIndex = 63;
//
// tbContent
//
this.tbContent.EditValue = "";
this.tbContent.Location = new System.Drawing.Point(128, 80);
this.tbContent.Name = "tbContent";
//
// tbContent.Properties
//
this.tbContent.Properties.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
this.tbContent.Size = new System.Drawing.Size(224, 21);
this.tbContent.TabIndex = 64;
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(80, 216);
this.btnSave.Name = "btnSave";
this.btnSave.TabIndex = 65;
this.btnSave.Text = "保存";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(232, 216);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 66;
this.btnCancel.Text = "取消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnNew
//
this.btnNew.Location = new System.Drawing.Point(232, 216);
this.btnNew.Name = "btnNew";
this.btnNew.TabIndex = 67;
this.btnNew.Text = "新建";
this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
//
// DictManageForm
//
this.AutoScroll = true;
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(131)), ((System.Byte)(194)), ((System.Byte)(231)));
this.Controls.Add(this.panelControl1);
this.Controls.Add(this.LVPanel);
this.Name = "DictManageForm";
this.Size = new System.Drawing.Size(672, 280);
((System.ComponentModel.ISupportInitialize)(this.LVPanel)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.panelControl1)).EndInit();
this.panelControl1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.tbId.Properties)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.tbContent.Properties)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region method
// 初始化字典下拉列表
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){
MessageBox.Show(ex.Message,"警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void InitiaListView(){
m_ListView.BackColor=Color.FromArgb(ShareClass.Rcolor,ShareClass.Gcolor,ShareClass.Bcolor);
m_ListView.InitLV_UserDefined(m_OtherInfoColumn,DisplayCol);
m_ListView.Dock = DockStyle.Fill;
m_ListView.Columns[0].Width = 40;
m_ListView.Columns[0].TextAlign = HorizontalAlignment.Left;
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;
int returnState = DynamicSave(o,methodName);
if(returnState>0){
MessageBox.Show("保存成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
UpdateStateData();
RefreshListView();
}
else{
MessageBox.Show("保存失败,序号或名称重复!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}catch(Exception ex){
MessageBox.Show("保存失败,"+ex.Message,"警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
/// <summary>
/// 动态保存,根据下拉表里的表名,去调相应的方法
/// </summary>
/// <param name="o">调用方法的类对象</param>
/// <param name="methodName">方法名</param>
private int DynamicSave(object o,string methodName){
System.Reflection.MethodInfo method;
method = o.GetType().GetMethod(methodName);
if(method!=null){
object[] parameters = {Id,Content};
return (int)method.Invoke(o,parameters);
}
return -1;
}
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){
MessageBox.Show(ex.Message);
return null;
}
}
private bool ValidateData(){
try{
this.m_Id = int.Parse(this.tbId.Text.Trim());
}catch(Exception ex){
MessageBox.Show(ex.Message);
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 + -