⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winpublic.cs

📁 利用AJAX实现目录树
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using Websharp.Base;
using Websharp.Service;

using System.IO;
namespace Ttyu.Win
{
	/// <summary>
	/// Public 的摘要说明。
	/// </summary>
	public class Public
	{
		//系统环境类的通用属性:

		//当前电脑名: 
		//		static System.Environment.MachineName;
		//		//当前电脑所属网域: 
		//		static System.Environment.UserDomainName;
		//		// 当前电脑用户: 
		//		static System.Environment.UserName;
		//在ASP.NET中专用属性:
		//获取服务器电脑名: Page.Server.ManchineName
		//获取用户信息: Page.User
		//获取客户端电脑名:Page.Request.UserHostName
		//获取客户端电脑IP: Page.Request.UserHostAddress

		//form 中容器类型名,这里是指能放其它控件且放的是输入数据的 控件
		//string ContainerNames=new string["GroupBox","Panel","TabControl","ToolBar"] ;
		string ContainerName="GroupBox,Panel,TabControl,ToolBar" ;
		//		public static EntityData mEntity;
		//		public static string mTable;
       
		public Public()
		{
		}



		//		'**********************************************
		//		'        
		//		'设置窗体中如TextBox,ComboBox,NumericUpDown,DateTimePicker等输入控件的有效性否
		//		'
		//		'*********************************************
		public void SetInputControlEnabled( System.Windows.Forms.Control  parentControlName, bool IsEnabled )
		{
			try
			{
				foreach(System.Windows.Forms.Control obj in parentControlName.Controls)
				{
					string objName=obj.GetType().Name;
					if (objName== "FpText")
					{
						obj.Enabled = IsEnabled;
						continue;
					}
					if ( objName== "TextBox" || objName== "ComboBox"|| objName== "NumericUpDown"|| objName== "DateTimePicker"|| objName== "Button"|| objName== "RadioButton"|| objName== "CheckBox"|| objName== "FpInteger"|| objName== "FpDouble"|| objName== "FpCurrency"|| objName== "FpMask")
						obj.Enabled = IsEnabled;
					if (obj.Controls.Count>0 )
						foreach(System.Windows.Forms.Control obj1 in obj.Controls)
						{
							string objName1=obj1.GetType().Name;
							if ( objName1== "TextBox" || objName1== "ComboBox"|| objName1== "NumericUpDown"|| objName1== "DateTimePicker"|| objName1== "Button"|| objName1== "RadioButton"|| objName1== "CheckBox")
								obj1.Enabled = IsEnabled;
						}
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
				return ;
			}
		}

		//		'**********************************************
		//		'        
		//		'设置窗体中如TextBox,ComboBox,NumericUpDown,DateTimePicker等输入控件的有效性否
		//		'
		//		'*********************************************
		public void ClearInputControl( System.Windows.Forms.Control  parentControlName)
		{
			try
			{
				foreach(System.Windows.Forms.Control obj in parentControlName.Controls)
				{
					string objName=obj.GetType().Name;
					if ( objName== "TextBox" || objName== "ComboBox"|| objName== "NumericUpDown"|| objName== "DateTimePicker"|| objName== "Button"|| objName== "CheckBox"|| objName== "FpInteger"|| objName== "FpDouble"|| objName== "FpCurrency"|| objName== "FpMask"|| objName== "FpText")
						obj.Text = "";
					if (obj.Controls.Count>0)
						foreach(System.Windows.Forms.Control obj1 in obj.Controls)
						{
							string objName1=obj1.GetType().Name;
							if ( objName1== "TextBox" || objName1== "ComboBox"|| objName1== "NumericUpDown"|| objName1== "DateTimePicker"|| objName1== "Button"|| objName1== "RadioButton"|| objName1== "CheckBox"|| objName== "FpInteger"|| objName== "FpDouble"|| objName== "FpCurrency"|| objName== "FpMask"|| objName== "FpText")
								obj1.Text = "";
						}
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
				return ;
			}
		}
		
		//		'**********************************************
		//		'        
		//		'设置ToolBar中"增加"、"保存"、"删除"等控件的有效性
		//		'
		//		'*********************************************
		public void SetToolBarButtonEnabled(ToolBarButton ToolBarName)
		{
			try
			{
				SetToolBarButton(ToolBarName.Parent ,false);
				switch( ToolBarName.Text )
				{
					case "撤消":
					case "删除":
					case "保存":
						foreach(ToolBarButton obj in ToolBarName.Parent.Buttons)
						{
							if ( obj.Text== "增加"||obj.Text== "退出" ) //||obj.Text== "Excel"||obj.Text== "打印"||obj.Text== "导出"||obj.Text== "批准"||obj.Text== "审核"||obj.Text== "日期"||obj.Text== "不批准"||obj.Text== "不审核"||obj.Text== "浏览"||obj.Text== "作废"||obj.Text== "导出")
							{
								obj.Enabled = true;
							}
						}
						break;
					case "增加":
						foreach(ToolBarButton obj in ToolBarName.Parent.Buttons)
						{
							if ( obj.Text== "保存"||obj.Text== "撤消" ||obj.Text== "批准"||obj.Text== "审核"||obj.Text== "日期"||obj.Text== "不批准"||obj.Text== "不审核"||obj.Text== "浏览"||obj.Text== "作废"||obj.Text== "导出")
							{
								obj.Enabled = true;
							}
						}
						break;
					case "将编辑":
						foreach(ToolBarButton obj in ToolBarName.Parent.Buttons)
						{
							if ( obj.Text== "增加" ||obj.Text== "编辑" ||obj.Text== "批准"||obj.Text== "审核"||obj.Text== "日期"||obj.Text== "不批准"||obj.Text== "不审核"||obj.Text== "浏览"||obj.Text== "作废"||obj.Text== "退出"||obj.Text== "复制")
							{
								obj.Enabled = true;
							}
						}
						break;
					case "编辑":
						foreach(ToolBarButton obj in ToolBarName.Parent.Buttons)
						{
							if ( obj.Text== "保存"||obj.Text== "撤消" )
							{
								obj.Enabled = true;
							}
						}
						break;
					case "打印":
						foreach(ToolBarButton obj in ToolBarName.Parent.Buttons)
						{
							if ( obj.Text== "保存")
							{
								obj.Enabled = true;
								break;
							}
						}
						break;
				
					case "更新":
						foreach(ToolBarButton obj in ToolBarName.Parent.Buttons)
						{
							if ( obj.Text== "保存"||obj.Text== "删除")
							{
								obj.Enabled = true;
							}
						}
						break;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
				return ;
			}
		}
		//设置ToolBar上的所有ToolBarButton的有效性				
		public static void SetToolBarButton(ToolBar ToolBarName,bool IsEnabled)
		{
			try
			{
				foreach(ToolBarButton obj in ToolBarName.Buttons)
				{
					string objName=obj.GetType().Name;
					if ( objName== "ToolBarButton")
						obj.Enabled = IsEnabled;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
				return ;
			}
		}																														
		 
		//把数据行写到输入控件上,这是按控件的TabIndex値对应数据行的列
		public void DataRowToControl(System.Windows.Forms.Control parentControl,DataRow DataRow,int BeginIndex)
		{
			try
			{
				//if(DataRow.RowState.ToString()=="Deleted") return;
				if (DataRow==null) return;
				System.Windows.Forms.Control obj=new System.Windows.Forms.Control ();
				for(int i=0;i<=DataRow.ItemArray.GetLength(0) - 1;i++)
				{
					object MyValue=DataRow[i];
					if (MyValue.ToString()=="") continue;
					if (MyValue!=null)
						foreach(System.Windows.Forms.Control obj2 in parentControl.Controls)
						{
							if ((obj2.Controls.Count>0) && (obj2.GetType().Name!="NumericUpDown") && (obj2.GetType().Name!="FpText"))
								foreach(System.Windows.Forms.Control obj1 in obj2.Controls)
								{
									if (obj1.TabIndex==i)
									{
										SetValue(obj1,MyValue)	;
										//obj1.Enabled=true; 
									}
								}

							else
							{
								if (obj2.TabIndex==i)
								{
									SetValue(obj2,MyValue);
									//obj2.Enabled=true; 
									break;
								}
							}
						}
				}
			
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
				return ;
			}
		}

		//把数据行写到输入控件上,这是按控件的TabIndex値对应数据行的列parent
		public void ControlToDataRow(System.Windows.Forms.Control parentControl,DataRow DRow,int BeginIndex)
		{
			try
			{
				for( int i=BeginIndex;i<DRow.Table.Columns.Count;i++ )
					foreach(System.Windows.Forms.Control obj2 in parentControl.Controls)
					{
						string ObjName=obj2.GetType().Name;
						if ((obj2.Controls.Count>0) && (ContainerName.IndexOf(ObjName)>=0))
						{
							foreach(System.Windows.Forms.Control obj1 in obj2.Controls)
								if (obj1.TabIndex==i)
								{
									//DRow[i]=obj1.Text; 
									DRow[i]=GetControlValue(obj1);
									break;
								}
						}
						else
							if (obj2.TabIndex==i )
						{
							//DRow[i]=obj2.Text; 
							DRow[i]=GetControlValue(obj2);
							break;
						}
					}
			}
			catch(Exception ex)
			{MessageBox.Show (ex.ToString ()); }
		}

		

		//设置控件的傎,完成格式转换
		private void SetValue(System.Windows.Forms.Control obj,object MyValue)
		{
			try
			{
				if(MyValue==System.DBNull.Value ) return ;
				if(MyValue==null) return ;
				if(MyValue.ToString()=="") return ;
				string objName=obj.GetType().Name;
				switch(objName)
				{
					case "ComboBox":
						ComboBox cbx=obj as ComboBox;
						if(cbx.DropDownStyle==ComboBoxStyle.DropDown||cbx.DropDownStyle==ComboBoxStyle.Simple)
							cbx.Text =MyValue.ToString();
						else
							cbx.SelectedIndex=(int)cbx.FindString(MyValue.ToString());
						break;
					case "CheckBox":
						CheckBox ckx=obj as CheckBox;
						ckx.Checked=(bool)MyValue  ;
						break;
					case "RadioButton":
						RadioButton rbt=obj as RadioButton;
						if ((int)MyValue==0)
							rbt.Checked=false;
						else
							rbt.Checked=true  ;
						break;
					case "TextBox":
						obj.Text =MyValue.ToString() ;
						break;
					case "UpDownButtons":
						//UpDownButtons nums=obj as UpDownButtons;
						//nums.Value =(int)MyValue ;
						break;
					case "NumericUpDown":
						NumericUpDown num=obj as NumericUpDown;
						num.Value =System.Convert .ToDecimal(MyValue );
						break;
					case "FpText":
						//					InputTextBox num=obj as InputTextBox;
						//					num.Value =(Decimal)MyValue ;
						obj.Text =MyValue.ToString () ;
						break;
					default:
						;

						//	((System.Windows.Forms.TextBox)(((System.Windows.Forms.UpDownBase)(num)).TextBox)).Text=num.Value.ToString();
						break;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
				return ;
			}
		}

	
		//在父容器中找到控件的TabIndex值为传入的TabIndex相等的控件
		public System.Windows.Forms.Control GetTabIndexControl(System.Windows.Forms.Control ParentObj,int TabIndex)
		{
			try

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -