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

📄 public.cs

📁 机械制造业信息管理系统(含源码) 是为一个粮仪厂开发的
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;

using System.Data;
using System.Data.OleDb;

using System.Windows;
using System.Windows.Forms;

using System.Drawing;
using System.Drawing.Drawing2D;

namespace Eboer.MIS.MF.WinForm
{
	/// <summary>
	/// Public 的摘要说明。
	/// </summary>
	public class Public
	{
		public Public(){}

		public static string          connStr = "";
		public static OleDbConnection conn    = null;
		public static string          cuUser  = "";
		public static string          userID  = "";
		public static string          passCH  = "";

		/// <summary>
		/// 
		/// </summary>
		public static string publicCorp    = "制造业企业信息管理系统";
		public static string publicAddress = "浙江省台州市路桥区";
		public static string publicTel     = "(+86)0576";
		public static string publicFax     = "(+86)0576";
        

		//系统编号不正确的提示
		public static string systemSignNotRight = "\n\n正确的格式为:四位数年份-两位数月份两位数日期-四位数的自动编号,例如:2005-0905-0001。";

		//当前选好的单位,或者说是默认的单位
		public static string currentSelfCorp = "2005-0901-0002";

		/// <summary>
		/// 粮仪厂图标
		/// </summary>
		public static Image  lyLogo = null;

		//MDI
		public static MainForm mainForm = null;

		//返回数据库连接
		public static void NewConn(){
			if(Public.conn == null || Public.conn.State.ToString().ToUpper() != "OPEN"){
				OleDbConnection conn = new OleDbConnection(Public.connStr);
				Public.conn          = conn;
			}
		}

		public static void CloseConn(){
			if(Public.conn != null && Public.conn.State.ToString().ToUpper() == "OPEN"){
				Public.conn.Close();
			}
		}

		/// <summary>
		/// 从库中获取指定的选择条目上
		/// </summary>
		/// <param name="dcSign"></param>
		/// <returns></returns>
		public static DataSet GetDireItem(string dcSign){
			DataSet ds = null;
			if(dcSign != null){
				try{
					string sql = "select * from DictionaryItem where dcSign='"+ dcSign +"' and diSign <> '' and diName <> ''";
					OleDbDataAdapter ad = new OleDbDataAdapter(sql,Public.conn);
					ds = new DataSet();
					ad.Fill(ds,"item");
				}catch{
					//
				}
			}
			return ds;
		}

		/// <summary>
		/// 分开客商名称和编号
		/// </summary>
		/// <param name="cor"></param>
		/// <param name="returnIndex"></param>
		/// <returns></returns>
		public static string CutCorString(string cor,int returnIndex){
			if(cor != null){
				int endIndex = cor.LastIndexOf("(");
				string val0 = cor.Substring(0,endIndex);
				string val1 = cor.Substring(endIndex+1,cor.Length -2-endIndex);

				if(returnIndex == 0) return val0;
				else                 return val1;

			}else{
				return null;
			}
		}

		/// <summary>
		/// 分开产品名称和编号
		/// </summary>
		/// <param name="cor"></param>
		/// <param name="returnIndex"></param>
		/// <returns></returns>
		public static string CutProString(string pro,int returnIndex){
			if(pro != null){
				int endIndex = pro.LastIndexOf("(");
				string val0 = pro.Substring(0,endIndex);
				string val1 = pro.Substring(endIndex+1,pro.Length -2-endIndex);

				if(returnIndex == 0) return val0;
				else                 return val1;

			}else{
				return null;
			}
		}

		/// <summary>
		/// 载入产品的选择框数据,编号|产品名称
		/// </summary>
		/// <returns></returns>
		public static ComboBox GetProList(ComboBox select){
			if(select != null){
				try{
					string sql = "select * from ProductCatalog order by treeID asc";
					OleDbDataAdapter ad = new OleDbDataAdapter(sql,Public.conn);
					DataSet ds = new DataSet();
					ad.Fill(ds,"pro");
					if(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0){
						for(int i=0;i<ds.Tables[0].Rows.Count;i++){
							DataRow row = ds.Tables[0].Rows[i];
							if(row["depth"].ToString() == "1"){
								select.Items.Add(row["gg"].ToString() + " " + row["signName"].ToString() + "("+ row["treeID"].ToString() +")");
								select = Public.SetProList(select,ds,row["autoID"].ToString());
							}
						}
					}
				}catch(Exception ex){
					MessageBox.Show(ex.Message.ToString());
					return select;
				}
			}
			return select;
		}

		public static ComboBox SetProList(ComboBox select,DataSet ds,string parentID){
			for(int i=0;i<ds.Tables[0].Rows.Count;i++){
				DataRow row = ds.Tables[0].Rows[i];
				if(row["parentID"].ToString() == parentID){
					string spaces = "";
					for(int n=0;n<Int32.Parse(row["depth"].ToString())-1;n++){
						spaces += "  ";
					}
					select.Items.Add(spaces + "|- " + row["gg"].ToString() + " " + row["signName"].ToString() + "("+ row["treeID"].ToString() +")");
					select = Public.SetProList(select,ds,row["autoID"].ToString());
				}
			}
			return select;
		}

		public static string RMB(string m) {
			string DX=m.ToString();
			int XSD=DX.IndexOf(".",0);
			string XP;
			if(XSD==-1) {
				XP=Public.RY(DX);    
			}else {
				string RX="";
				string DX1=DX.Substring(0,XSD);
				XP=Public.RY(DX1);
				string DX2=DX.Substring(XSD,DX.Length-XSD).Substring(1);
				if(DX2.Length==1)
					if (DX2[0]!='0')
						RX=Public.HZ(DX2[0])+"角零分";
				if(DX2.Length==2) {  
					if(DX2[1]=='0'&& DX2[0]=='0'){
						RX = "整";
					}else if(DX2[1]!='0'&& DX2[0]!='0')
						RX=Public.HZ(DX2[0])+"角"+Public.HZ(DX2[1])+"分";
					else
						if(DX2[0]=='0')
							RX="零" + Public.HZ(DX2[1])+"分";
						else
							RX=Public.HZ(DX2[0])+"角零分";
				}
				XP=XP+RX;
			}

			if(XP.EndsWith("元")) XP += "整";

			return XP.Replace("拾零万","拾万").Replace("拾零元","拾元").Replace("仟零零零元整","仟元整").Replace("佰零零元整","佰元整").Replace("万零零零零元","万元整");
		}
		public static string RY(string DX) {
			string R="";
			int l=DX.Length;
			if(DX=="0") return R;
			int b=0;
			for(int i=0;i<DX.Length;i++) {
				int  m=DX.Length-i;
				R=R+Public.HZ(DX[i]);
				if(b==0 && DX[i]=='0'&& m!=5 && m!=1 && i<DX.Length-1) {
					bool p=true;
					for(int k=i+1;k<DX.Length;k++) {
						if(DX[k]=='0') p=false; 
					}
					if(p==true) {
						R=R+"零";
						b=1;
					}
				}
				if(m==8 && DX[i]!='0') R=R+"仟";
				if(m==7 && DX[i]!='0') R=R+"佰";
				if(m==6 && DX[i]!='0') R=R+"拾";
				if(m==5 ) R=R+"万";
				if(m==4 && DX[i]!='0') R=R+"仟";
				if(m==3 && DX[i]!='0') R=R+"佰";
				if(m==2 && DX[i]!='0') R=R+"拾";
				if(m==1) R=R+"元";
			}
			return R;
		}

		public static string HZ(char num) {
			switch(num) {
				case '1': return "壹";
				case '2': return "贰";
				case '3': return "叁";
				case '4': return "肆";
				case '5': return "伍";
				case '6': return "陆";
				case '7': return "柒";
				case '8': return "捌";
				case '9': return "玖";
				default : return "零";
			}
		}

		/// <summary>
		/// 将金额小数点后两位加上
		/// </summary>
		/// <param name="jr"></param>
		/// <returns></returns>
		public static string NewJR(string jr){
			if(jr != null){
				int index = jr.IndexOf(".");
				if(index == -1) jr += ".00";
				if(jr.Length - index == 2) jr += "0";
				if(jr.Length - index == 1) jr += "00";

				//jr = jr.ToString().Replace(".00","");
			}
			return jr;
		}

		/// <summary>
		/// 调整DataGrid整行的高度
		/// </summary>
		/// <param name="dg"></param>
		/// <param name="colName"></param>
		public static void ReSetGridCellHeight(DataGrid dg,string tableName){
			//DataGridTableStyle dgts = new DataGridTableStyle();
			//dgts.PreferredRowHeight = 25;
			//dgts.MappingName = ((DataTable)dg.DataSource).TableName;
			//dg.TableStyles.Add(dgts);
		}

		/// <summary>
		/// 返回最新的自动编号
		/// </summary>
		/// <returns></returns>
		public static string GetNewInfoID(string tableName,string fieldName){

			//前部分的日期
			string result = DateTime.Now.Year.ToString() + "-" + Public.SetStartZero(DateTime.Now.Month.ToString(),2) + Public.SetStartZero(DateTime.Now.Day.ToString(),2);

			try{
				string sql = "select top 1 "+ fieldName +" from " + tableName + " where "+ fieldName +" like '"+ result +"%' order by autoID desc";
				OleDbDataAdapter ad = new OleDbDataAdapter(sql,Public.conn);
				DataSet ds = new DataSet();
				ad.Fill(ds,"info");
				if(ds.Tables["info"].Rows.Count == 0){
					result += "-0001";
				}else{
					string _val = ds.Tables[0].Rows[0][fieldName].ToString();
					int    _num = Int32.Parse(_val.Substring(_val.LastIndexOf("-")+1,_val.Length-_val.LastIndexOf("-")-1));

					_num ++;

					result += "-" + Public.SetStartZero(_num.ToString(),4);
				}

			}catch(Exception ex){
				MessageBox.Show("不能自动获取信息编号,系统返回错误:" + ex.Message.ToString());
				return null;
			}

			return result;
		}

⌨️ 快捷键说明

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