You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1084 lines
44 KiB
1084 lines
44 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Data;
|
|
using System.Reflection;
|
|
using System.Data.SqlClient;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
//using System.Windows.Forms;
|
|
using System.Data.OleDb;
|
|
using System.CodeDom.Compiler;
|
|
using System.CodeDom;
|
|
//using System.Web.Services.Description;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class APPConfigForOracl
|
|
{
|
|
public class AppConfig
|
|
{
|
|
#region 数据库连接符
|
|
|
|
/// <summary>
|
|
/// 框架数据库连接
|
|
/// </summary>
|
|
public static string FrameConnectString = "";
|
|
/// <summary>
|
|
/// 实际应用软件的数据库连接
|
|
/// </summary>
|
|
public static string AppConnectString = "";
|
|
#endregion
|
|
#region 用户登陆时提供的信息
|
|
/// <summary>
|
|
/// 用户的唯一标识
|
|
/// </summary>
|
|
public static string UserId = "";
|
|
/// <summary>
|
|
/// 当前登陆用户账户
|
|
/// </summary>
|
|
public static string UserCode = "";
|
|
/// <summary>
|
|
/// 当前登陆用户姓名
|
|
/// </summary>
|
|
public static string UserName = "";
|
|
/// <summary>
|
|
/// 当前登陆用户口令(加密)
|
|
/// </summary>
|
|
public static string UserPwd = "";
|
|
/// <summary>
|
|
/// 站点编号
|
|
/// </summary>
|
|
public static string WorkPointCode = "";
|
|
/// <summary>
|
|
/// 站点名称
|
|
/// </summary>
|
|
public static string WorkPointName = "";
|
|
/// <summary>
|
|
/// 当前用户是否管理员
|
|
/// </summary>
|
|
public static bool AdminFlag = false;
|
|
/// <summary>
|
|
/// 公司名称
|
|
/// </summary>
|
|
public static string CompanyName = "";
|
|
|
|
/// <summary>
|
|
/// 当前语言包 1代表简体 2 代表繁体 3代表英文
|
|
/// </summary>
|
|
public static string LangIndex = "1";
|
|
|
|
///// <summary>
|
|
///// 转换规则
|
|
///// </summary>
|
|
//public static string LangConvert = "";
|
|
|
|
/// <summary>
|
|
/// 基础服务的路径
|
|
/// </summary>
|
|
public static string BaseServicePath = System.AppDomain.CurrentDomain.BaseDirectory + "\\BaseServiceConfig\\";
|
|
|
|
/// <summary>
|
|
/// 基础服务设置文件
|
|
/// </summary>
|
|
public static string BaseServiceFile = BaseServicePath + "baseserviceurl.ini";
|
|
/// <summary>
|
|
/// 登录时保存路径
|
|
/// </summary>
|
|
public static string LoginConfigPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\LoginConfig\\";
|
|
|
|
/// <summary>
|
|
/// 登录时保存文件
|
|
/// </summary>
|
|
public static string LoginConfigFile = LoginConfigPath + "loginconfig.ini";
|
|
/// <summary>
|
|
/// 语言库设置路径
|
|
/// </summary>
|
|
public static string LanguageConfigPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\Language\\";
|
|
/// <summary>
|
|
/// 语言包XML
|
|
/// </summary>
|
|
public static string LanguageConfigFile = LanguageConfigPath + "lang.xml";
|
|
/// <summary>
|
|
/// 默认语言文件
|
|
/// </summary>
|
|
public static string LanguageConfigDefaultStyle = LanguageConfigPath + "defaultlang.ini";
|
|
/// <summary>
|
|
/// 图片资源路径
|
|
/// </summary>
|
|
public static string ResourcePath = System.AppDomain.CurrentDomain.BaseDirectory + "\\Resource\\";
|
|
|
|
/// <summary>
|
|
/// 新版图片资源
|
|
/// </summary>
|
|
public static string ImagesPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\Images\\";
|
|
|
|
/// <summary>
|
|
/// 系统图片
|
|
/// </summary>
|
|
//public static ImageList SysImageList = new ImageList();
|
|
|
|
/// <summary>
|
|
/// 新版系统图片
|
|
/// </summary>
|
|
//public static ImageList NewSysImageList = new ImageList();
|
|
|
|
/// <summary>
|
|
/// 新版系统图片
|
|
/// </summary>
|
|
//public static TabControl tc;
|
|
|
|
/// <summary>
|
|
/// 当前登陆设备
|
|
/// </summary>
|
|
public static string EQPCode = "";
|
|
|
|
/// <summary>
|
|
/// 当前登陆工序
|
|
/// </summary>
|
|
public static string OPCode = "";
|
|
|
|
/// <summary>
|
|
/// 当前登陆资源
|
|
/// </summary>
|
|
public static string RESCode = "";
|
|
|
|
#endregion
|
|
#region 字符串加解密
|
|
/// <summary>
|
|
/// MD5加密
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
public static string ToMd5(string str)
|
|
{
|
|
return Encrypt(str, "&%#@?,:*_");
|
|
}
|
|
/// <summary>
|
|
/// MD5解密
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
public static string FromMd5(string str)
|
|
{
|
|
return Decrypt(str, "&%#@?,:*_");
|
|
}
|
|
/// <summary>
|
|
/// 加密
|
|
/// </summary>
|
|
/// <param name="strText"></param>
|
|
/// <param name="strEncrKey"></param>
|
|
/// <returns></returns>
|
|
private static String Encrypt(String strText, String strEncrKey)
|
|
{
|
|
|
|
Byte[] byKey = { };
|
|
Byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
|
try
|
|
{
|
|
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8));
|
|
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
|
Byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
|
|
MemoryStream ms = new MemoryStream();
|
|
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV),
|
|
CryptoStreamMode.Write);
|
|
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
|
cs.FlushFinalBlock();
|
|
return Convert.ToBase64String(ms.ToArray());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 解密
|
|
/// </summary>
|
|
/// <param name="strText"></param>
|
|
/// <param name="sDecrKey"></param>
|
|
/// <returns></returns>
|
|
private static String Decrypt(String strText, String sDecrKey)
|
|
{
|
|
|
|
Byte[] byKey = { };
|
|
Byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
|
|
Byte[] inputByteArray = new byte[strText.Length];
|
|
try
|
|
{
|
|
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 8));
|
|
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
|
inputByteArray = Convert.FromBase64String(strText);
|
|
MemoryStream ms = new MemoryStream();
|
|
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV),
|
|
CryptoStreamMode.Write);
|
|
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
|
cs.FlushFinalBlock();
|
|
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
|
|
return encoding.GetString(ms.ToArray());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
}
|
|
#endregion
|
|
#region 获取服务器时间
|
|
public static DateTime GetSeverDateTime(string formatString)
|
|
{
|
|
string dateSql = "SELECT getdate()";
|
|
return Convert.ToDateTime(Convert.ToDateTime(DBHelper.ExecuteScalar(FrameConnectString, CommandType.Text, dateSql).ToString()).ToString(formatString));
|
|
}
|
|
public static double GetDateDiffForDays(string sDate, string dDate)
|
|
{
|
|
string sql = "SELECT DATEDIFF(DAY,'" + sDate + "','" + dDate + "')";
|
|
object obj = DBHelper.ExecuteScalar(AppConfig.FrameConnectString, CommandType.Text, sql);
|
|
return Convert.ToDouble(obj);
|
|
}
|
|
#endregion
|
|
#region 获取唯一GUID
|
|
public static string GetGuid()
|
|
{
|
|
return Guid.NewGuid().ToString();
|
|
}
|
|
#endregion
|
|
#region WCF基本参数
|
|
/// <summary>
|
|
/// 基础服务WCF路径
|
|
/// </summary>
|
|
public static string BaseServiceUri = "";
|
|
|
|
|
|
#endregion
|
|
#region 获取本机器信息
|
|
/// <summary>
|
|
/// 获取本地IP地址
|
|
/// </summary>
|
|
/// <returns>IP地址</returns>
|
|
public static string GetIpAddress()
|
|
{
|
|
string ipstr = "";
|
|
IPAddress[] arrIPAddresses = Dns.GetHostAddresses(Dns.GetHostName());
|
|
foreach (IPAddress ip in arrIPAddresses)
|
|
{
|
|
if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))
|
|
{
|
|
ipstr = ip.ToString();
|
|
}
|
|
}
|
|
return ipstr;
|
|
}
|
|
public static string GetComputerName()
|
|
{
|
|
string ip = GetIpAddress();
|
|
IPHostEntry hostInfo = Dns.GetHostByAddress(ip);
|
|
return hostInfo.HostName;
|
|
}
|
|
public static string GetHostName()
|
|
{
|
|
return Dns.GetHostName();
|
|
}
|
|
#endregion
|
|
#region 判断是否是端口格式
|
|
/// <summary>
|
|
/// 判断是否是端口号
|
|
/// </summary>
|
|
/// <param name="port"></param>
|
|
/// <returns></returns>
|
|
public static bool CheckIsPort(string port)
|
|
{
|
|
bool isPort = false;
|
|
int portNum;
|
|
isPort = Int32.TryParse(port, out portNum);
|
|
if (isPort && portNum >= 0 && portNum <= 65535)
|
|
{
|
|
isPort = true;
|
|
}
|
|
else
|
|
{
|
|
isPort = false;
|
|
}
|
|
return isPort;
|
|
}
|
|
#endregion
|
|
#region 测试连接符是否能够连接
|
|
/// <summary>
|
|
/// 测试连接符是否成功
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
public static bool CheckDbConnectionState(string str)
|
|
{
|
|
bool flag = false;
|
|
try
|
|
{
|
|
using (SqlConnection conn = new SqlConnection(str))
|
|
{
|
|
conn.Open();
|
|
if (conn.State == ConnectionState.Open)
|
|
{
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
flag = false;
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
flag = false;
|
|
}
|
|
return flag;
|
|
}
|
|
#endregion
|
|
#region 反射窗体
|
|
//通用窗体入口
|
|
public struct ChildWinManagement
|
|
{
|
|
public static string WinCaption(string r) { return r; }
|
|
//public static bool ExistWin(Form MDIwin, string caption) { bool R = false; foreach (Form f in MDIwin.MdiChildren) { if (f.Name + f.Text == caption) { R = true; f.Show(); f.Activate(); break; } } return R; }
|
|
}
|
|
//系统入口方法
|
|
//public static void CreateFormShow(string MDll, string MCode, string MName, string MForm, bool IsShowDialog, Form MainForm, string FormKeyValue, bool maxFlag)
|
|
//{
|
|
// try
|
|
// {
|
|
// bool canEnterFlag = GetUserExcuteRight(MCode, "see");
|
|
// if (canEnterFlag == false)
|
|
// {
|
|
// MessageBox.Show("对不起,您无权限使用该功能!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
// return;
|
|
// }
|
|
// Form f = new Form();
|
|
|
|
// string typeName = MDll + "." + MForm;
|
|
// Assembly assembly = Assembly.LoadFrom(Application.StartupPath + @"\" + MDll + ".dll");
|
|
// // 实例化窗体
|
|
// Type t = assembly.GetType(typeName);
|
|
|
|
// if (!string.IsNullOrEmpty(FormKeyValue))
|
|
// {
|
|
// FormKeyValue = FormKeyValue.Substring(0, FormKeyValue.Length - 1);
|
|
// object[] strs = FormKeyValue.Split(',');
|
|
// f = Activator.CreateInstance(t, strs) as Form;
|
|
// }
|
|
// else
|
|
// {
|
|
// f = Activator.CreateInstance(t) as Form;
|
|
// }
|
|
// f.Name = MForm;
|
|
// f.Tag = MCode;
|
|
// if (MainForm == null)
|
|
// {
|
|
// f.Text = MName;
|
|
// f.WindowState = (maxFlag == true ? FormWindowState.Maximized : FormWindowState.Normal);
|
|
// f.Text = MName;
|
|
// f.Tag = MCode;
|
|
// f.ShowDialog();
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// if (!ChildWinManagement.ExistWin(MainForm, f.Name + MName))
|
|
// {
|
|
// if (IsShowDialog == false)
|
|
// {
|
|
// f.MdiParent = MainForm;
|
|
// f.WindowState = FormWindowState.Maximized;
|
|
// f.Text = MName;
|
|
// f.Tag = MCode;
|
|
// f.Show();
|
|
// }
|
|
// else
|
|
// {
|
|
// f.WindowState = (maxFlag == true ? FormWindowState.Maximized : FormWindowState.Normal);
|
|
// f.Text = MName;
|
|
// f.Tag = MCode;
|
|
// f.ShowDialog();
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw ex;
|
|
// }
|
|
//}
|
|
|
|
|
|
//系统入口方法
|
|
//public static void CloseFormShow(string MName)
|
|
//{
|
|
// try
|
|
// {
|
|
// if (tc != null)
|
|
// {
|
|
// foreach (TabPage tab in tc.TabPages)
|
|
// {
|
|
// if (tab.Text == MName)
|
|
// {
|
|
// tc.TabPages.Remove(tab);
|
|
// tc.Refresh();
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw ex;
|
|
// }
|
|
|
|
//}
|
|
|
|
#endregion
|
|
#region DataTable分页
|
|
/**/
|
|
/// <summary>
|
|
/// 根据索引和pagesize返回记录
|
|
/// </summary>
|
|
/// <param name="dt">记录集 DataTable</param>
|
|
/// <param name="PageIndex">当前页</param>
|
|
/// <param name="pagesize">一页的记录数</param>
|
|
/// <returns></returns>
|
|
public static DataTable GetPageData(DataTable dt, int PageIndex, int PageSize)
|
|
{
|
|
|
|
if (PageIndex == 0)
|
|
return dt;
|
|
DataTable newdt = dt.Clone();
|
|
//newdt.Clear();
|
|
int rowbegin = (PageIndex - 1) * PageSize;
|
|
int rowend = PageIndex * PageSize;
|
|
|
|
if (rowbegin >= dt.Rows.Count)
|
|
return newdt;
|
|
|
|
if (rowend > dt.Rows.Count)
|
|
rowend = dt.Rows.Count;
|
|
for (int i = rowbegin; i <= rowend - 1; i++)
|
|
{
|
|
DataRow newdr = newdt.NewRow();
|
|
DataRow dr = dt.Rows[i];
|
|
foreach (DataColumn column in dt.Columns)
|
|
{
|
|
newdr[column.ColumnName] = dr[column.ColumnName];
|
|
}
|
|
newdt.Rows.Add(newdr);
|
|
}
|
|
|
|
return newdt;
|
|
}
|
|
#endregion
|
|
#region 获取数据源连接符
|
|
/// <summary>
|
|
/// 数据源ID(GUID)
|
|
/// </summary>
|
|
/// <param name="dbId"></param>
|
|
/// <returns></returns>
|
|
public static string GetDataBaseConnectString(string dbId)
|
|
{
|
|
string retString = "";
|
|
|
|
string sql = @"SELECT DBSourceName ,
|
|
DBIpAddress ,
|
|
DBName ,
|
|
DBUser ,
|
|
DBPwd
|
|
FROM dbo.Sys_DataBase
|
|
WHERE WorkCode = '{0}'
|
|
AND ID = '{1}'";
|
|
sql = string.Format(sql, AppConfig.WorkPointCode, dbId);
|
|
DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, sql).Tables[0];
|
|
if (data.Rows.Count == 0)
|
|
{
|
|
retString = "";
|
|
}
|
|
else
|
|
{
|
|
string foramtString = "Data Source={0};Database={1};Uid={2};Pwd={3};";
|
|
string dbIpAddress = data.Rows[0]["DBIpAddress"].ToString();
|
|
string dbName = data.Rows[0]["DBName"].ToString();
|
|
string dbUser = data.Rows[0]["DBUser"].ToString();
|
|
string dbPwd = data.Rows[0]["DBPwd"].ToString();
|
|
retString = string.Format(foramtString, new object[] { dbIpAddress, dbName, dbUser, AppConfig.FromMd5(dbPwd) });
|
|
}
|
|
|
|
return retString;
|
|
|
|
}
|
|
#endregion
|
|
#region 权限判断
|
|
/// <summary>
|
|
/// 窗体按钮权限
|
|
/// </summary>
|
|
/// <param name="menuCode">窗体TAG值</param>
|
|
/// <param name="btnName">按钮名称</param>
|
|
/// <returns>false or true</returns>
|
|
public static bool GetUserExcuteRight(string menuCode, string btnName)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"DECLARE @Count INT
|
|
SET @Count = 0
|
|
SELECT @Count = COUNT(*)
|
|
FROM dbo.Sys_UserPower a WITH ( NOLOCK )
|
|
LEFT JOIN dbo.Sys_MenuAction b ON a.ActionId = b.ID
|
|
WHERE UserId = '{0}'
|
|
AND b.WorkPointCode = '{1}'
|
|
AND b.MenuCode = '{2}'
|
|
AND b.BtnName = '{3}'
|
|
DECLARE @Count1 INT
|
|
SET @Count1 = 0
|
|
SELECT @Count1 = COUNT(*)
|
|
FROM dbo.Sys_RolePower a WITH ( NOLOCK )
|
|
LEFT JOIN dbo.Sys_MenuAction b WITH ( NOLOCK ) ON a.ActionId = b.ID
|
|
WHERE a.RoleId IN ( SELECT ISNULL(a.RoleId, 0)
|
|
FROM dbo.Sys_UserRole a WITH ( NOLOCK )
|
|
WHERE a.UserId = '{0}' )
|
|
AND b.WorkPointCode = '{1}'
|
|
AND b.MenuCode = '{2}'
|
|
AND b.BtnName = '{3}'
|
|
SELECT @Count + @Count1
|
|
";
|
|
sql = string.Format(sql, new object[] { AppConfig.UserId, AppConfig.WorkPointCode, menuCode, btnName });
|
|
object obj = DBHelper.ExecuteScalar(AppConfig.FrameConnectString, CommandType.Text, sql);
|
|
bool flag = false;
|
|
if (AppConfig.UserCode.ToLower() == "demo")
|
|
{
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
if (AppConfig.AdminFlag == true)
|
|
{
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
flag = (Convert.ToInt32(obj) > 0 ? true : false);
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
#region 获取结构ID&&数据源Id
|
|
/// <summary>
|
|
/// 返回窗体结构ID
|
|
/// </summary>
|
|
/// <param name="menuCode">tagcode</param>
|
|
/// <returns></returns>
|
|
public static string GetMenuId(string menuCode)
|
|
{
|
|
string sql = "SELECT ID FROM dbo.Sys_Menu WHERE WorkPointCode='{0}' AND MenuCode='{1}'";
|
|
sql = string.Format(sql, AppConfig.WorkPointCode, menuCode);
|
|
object obj = DBHelper.ExecuteScalar(AppConfig.FrameConnectString, CommandType.Text, sql);
|
|
return obj == null ? "" : obj.ToString();
|
|
}
|
|
/// <summary>
|
|
/// 获取数据源ID
|
|
/// </summary>
|
|
/// <param name="menuCode"></param>
|
|
/// <param name="filterbtnNmae"></param>
|
|
/// <returns></returns>
|
|
public static string GetSourceId(string menuCode, string filterbtnNmae)
|
|
{
|
|
string sql = " SELECT ID FROM dbo.Sys_FormDataSource WHERE MenuId='{0}' AND FilterButtonName='{1}'";
|
|
sql = string.Format(sql, GetMenuId(menuCode), filterbtnNmae);
|
|
object obj = DBHelper.ExecuteScalar(AppConfig.FrameConnectString, CommandType.Text, sql);
|
|
return obj == null ? "" : obj.ToString();
|
|
}
|
|
public static DataSet GetDataSourceDefaultDataSet(string menuCode, string filterbtnName)
|
|
{
|
|
string sql = "SELECT SysDataSourceFlag,DbId,SqlTxt FROM dbo.Sys_FormDataSource WHERE MenuId='{0}' AND FilterButtonName='{1}'";
|
|
sql = string.Format(sql, GetMenuId(menuCode), filterbtnName);
|
|
DataSet ds = null;
|
|
DataRow dr = null;
|
|
try
|
|
{
|
|
|
|
DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, sql).Tables[0];
|
|
if (data.Rows.Count > 0)
|
|
{
|
|
dr = data.Rows[0];
|
|
}
|
|
if (dr != null)
|
|
{
|
|
bool sysFlag = Convert.ToBoolean(dr["SysDataSourceFlag"]);
|
|
string dbid = dr["DbId"].ToString();
|
|
string sqltxt = dr["SqlTxt"].ToString();
|
|
string conStr = "";
|
|
if (sysFlag == true)
|
|
{
|
|
conStr = AppConfig.AppConnectString;
|
|
}
|
|
else
|
|
{
|
|
conStr = GetDataBaseConnectString(dbid);
|
|
}
|
|
ds = DBHelper.ExecuteDataset(conStr, CommandType.Text, sqltxt);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ds = null;
|
|
}
|
|
return ds;
|
|
}
|
|
#endregion
|
|
#region EXCEL
|
|
public static DataTable GetExcelData(string excelPath, string sheetName)
|
|
{
|
|
DataTable dtGBPatient = new DataTable();
|
|
|
|
string strConn;
|
|
|
|
//注意:把一个excel文件看做一个数据库,一个sheet看做一张表。语法 "SELECT * FROM [sheet1$]",表单要使用"[]"和"$"
|
|
|
|
// 1、HDR表示要把第一行作为数据还是作为列名,作为数据用HDR=no,作为列名用HDR=yes;
|
|
// 2、通过IMEX=1来把混合型作为文本型读取,避免null值。
|
|
strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source={0};Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";
|
|
string strConnection = string.Format(strConn, excelPath);
|
|
OleDbConnection conn = new OleDbConnection(strConnection);
|
|
conn.Open();
|
|
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetName + "$]", strConnection);
|
|
|
|
dtGBPatient.TableName = "gbPatientInfo";
|
|
oada.Fill(dtGBPatient);//获得datatable
|
|
conn.Close();
|
|
return dtGBPatient;
|
|
|
|
}
|
|
//public static string[] GetExcelSheetNames(string filePath)
|
|
//{
|
|
|
|
//Microsoft.Office.Interop.Excel.ApplicationClass
|
|
//excelApp
|
|
//=
|
|
//new
|
|
//Microsoft.Office.Interop.Excel.ApplicationClass();
|
|
|
|
//Microsoft.Office.Interop.Excel.Workbooks
|
|
//wbs
|
|
//=
|
|
//excelApp.Workbooks;
|
|
//Microsoft.Office.Interop.Excel.Workbook
|
|
//wb
|
|
//=
|
|
//wbs.Open(filePath,
|
|
//Type.Missing, Type.Missing, Type.Missing, Type.Missing,
|
|
//Type.Missing,
|
|
//Type.Missing,
|
|
//Type.Missing,
|
|
//Type.Missing,
|
|
//Type.Missing, Type.Missing,
|
|
|
|
//Type.Missing, Type.Missing, Type.Missing, Type.Missing);
|
|
|
|
//int count = wb.Worksheets.Count;
|
|
//string[] names = new string[count];
|
|
//for (int i = 1; i <= count; i++)
|
|
//{
|
|
|
|
// names[i - 1]
|
|
// =
|
|
// ((Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[i]).Name;
|
|
//}
|
|
|
|
//wb.Close(null, null, null);
|
|
//excelApp.Quit();
|
|
//wbs.Close();
|
|
//System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
|
|
//System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
|
|
//System.Runtime.InteropServices.Marshal.ReleaseComObject(wbs);
|
|
//excelApp = null;
|
|
//wbs = null;
|
|
//wb = null;
|
|
//return names;
|
|
|
|
//}
|
|
|
|
#endregion
|
|
#region 获取单据流水号
|
|
/// <summary>
|
|
/// 获取单据号
|
|
/// </summary>
|
|
/// <param name="tbName"></param>
|
|
/// <param name="colName"></param>
|
|
/// <param name="Pre"></param>
|
|
/// <param name="numLen"></param>
|
|
/// <returns></returns>
|
|
public static string GetBillCode(string tbName, string colName, string Pre, int numLen)
|
|
{
|
|
string sql = "EXEC Addins_GetBillCode '{0}','{1}','{2}',{3}";
|
|
sql = string.Format(sql, new object[] { tbName, colName, Pre, numLen });
|
|
return DBHelper.ExecuteScalar(AppConfig.AppConnectString, CommandType.Text, sql).ToString();
|
|
}
|
|
/// <summary>
|
|
/// 获取单据号
|
|
/// </summary>
|
|
/// <param name="tbName"></param>
|
|
/// <param name="colName"></param>
|
|
/// <param name="Pre"></param>
|
|
/// <param name="numLen"></param>
|
|
/// <returns></returns>
|
|
public static string GetSerialCode(string connectString, string tbName, string colName, string Pre, int numLen)
|
|
{
|
|
string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}',{3}";
|
|
sql = string.Format(sql, new object[] { tbName, colName, Pre, numLen });
|
|
return DBHelper.ExecuteScalar(connectString, CommandType.Text, sql).ToString();
|
|
}
|
|
#endregion
|
|
#region 获取物料批次
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="invCode"></param>
|
|
/// <returns></returns>
|
|
public static string GetMaxNum(string invCode)
|
|
{
|
|
string sql = @"DECLARE @Num INT
|
|
SET @Num = 0
|
|
SELECT @Num = ISNULL(MAX(MAXNUM), 0)
|
|
FROM dbo.TBLBARCODEBATCH
|
|
WHERE DATEINDEX = '{0}'
|
|
AND InvCode = '{1}'
|
|
|
|
IF @Num = 0
|
|
BEGIN
|
|
INSERT INTO dbo.TBLBARCODEBATCH
|
|
( InvCode, DateIndex, MaxNum )
|
|
VALUES ( '{1}', '{0}', @Num + 1 )
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
UPDATE dbo.TBLBARCODEBATCH SET maxnum=@Num+1 WHERE invcode='{1}' AND dateindex='{0}'
|
|
END
|
|
SELECT @Num+1";
|
|
string dateIndex = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm").ToString("yyyyMMddHHmm");
|
|
sql = string.Format(sql, dateIndex, invCode);
|
|
object obj = DBHelper.ExecuteScalar(AppConfig.AppConnectString, CommandType.Text, sql);
|
|
return dateIndex + Convert.ToInt32(obj).ToString("0000");
|
|
}
|
|
#endregion
|
|
#region 调用WEBSERVICE
|
|
/**/
|
|
/// 根据指定的信息,调用远程WebService方法
|
|
///
|
|
/// WebService的http形式的地址
|
|
/// 欲调用的WebService的命名空间
|
|
/// 欲调用的WebService的类名(不包括命名空间前缀)
|
|
/// 欲调用的WebService的方法名
|
|
/// 参数列表
|
|
/// WebService的执行结果
|
|
///
|
|
/// 如果调用失败,将会抛出Exception。请调用的时候,适当截获异常。
|
|
/// 异常信息可能会发生在两个地方:
|
|
/// 1、动态构造WebService的时候,CompileAssembly失败。
|
|
/// 2、WebService本身执行失败。
|
|
///
|
|
///
|
|
///
|
|
/// object obj = InvokeWebservice("http://localhost/GSP_WorkflowWebservice/common.asmx","Genersoft.Platform.Service.Workflow","Common","GetToolType",new object[]{"1"});
|
|
///
|
|
///
|
|
//public static object InvokeWebservice(string url, string @namespace, string classname, string methodname, object[] args)
|
|
//{
|
|
//try
|
|
//{
|
|
// System.Net.WebClient wc = new System.Net.WebClient();
|
|
// System.IO.Stream stream = wc.OpenRead(url + "?WSDL");
|
|
// System.Web.Services.Description.ServiceDescription sd = System.Web.Services.Description.ServiceDescription.Read(stream);
|
|
// System.Web.Services.Description.ServiceDescriptionImporter sdi = new System.Web.Services.Description.ServiceDescriptionImporter();
|
|
// sdi.AddServiceDescription(sd, "", "");
|
|
// System.CodeDom.CodeNamespace cn = new System.CodeDom.CodeNamespace(@namespace);
|
|
// System.CodeDom.CodeCompileUnit ccu = new System.CodeDom.CodeCompileUnit();
|
|
// ccu.Namespaces.Add(cn);
|
|
// sdi.Import(cn, ccu);
|
|
|
|
// Microsoft.CSharp.CSharpCodeProvider csc = new Microsoft.CSharp.CSharpCodeProvider();
|
|
// System.CodeDom.Compiler.ICodeCompiler icc = csc.CreateCompiler();
|
|
|
|
// System.CodeDom.Compiler.CompilerParameters cplist = new System.CodeDom.Compiler.CompilerParameters();
|
|
// cplist.GenerateExecutable = false;
|
|
// cplist.GenerateInMemory = true;
|
|
// cplist.ReferencedAssemblies.Add("System.dll");
|
|
// cplist.ReferencedAssemblies.Add("System.XML.dll");
|
|
// cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
|
|
// cplist.ReferencedAssemblies.Add("System.Data.dll");
|
|
|
|
// System.CodeDom.Compiler.CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
|
|
// if (true == cr.Errors.HasErrors)
|
|
// {
|
|
// System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
// foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
|
|
// {
|
|
// sb.Append(ce.ToString());
|
|
// sb.Append(System.Environment.NewLine);
|
|
// }
|
|
// throw new Exception(sb.ToString());
|
|
// }
|
|
// System.Reflection.Assembly assembly = cr.CompiledAssembly;
|
|
// Type t = assembly.GetType(@namespace + "." + classname, true, true);
|
|
// object obj = Activator.CreateInstance(t);
|
|
// System.Reflection.MethodInfo mi = t.GetMethod(methodname);
|
|
// return mi.Invoke(obj, args);
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
|
|
//}
|
|
//}
|
|
#endregion
|
|
#region 默认站点采集点
|
|
public static string DefaultLine = "";
|
|
public static string DefaultRes = "";
|
|
#endregion
|
|
#region 获取连接符中的数据库名称
|
|
public static string GetDataBaseNameByConnectString(string connectString)
|
|
{
|
|
Dictionary<string, string> dictionary = connectString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToDictionary(x => x.Split('=')[0], x => x.Split('=')[1]);
|
|
string erpDataBase = dictionary["Database"];
|
|
return erpDataBase;
|
|
}
|
|
#endregion
|
|
#region 获取打印次数
|
|
/// <summary>
|
|
/// 返回打印次数
|
|
/// </summary>
|
|
/// <param name="printTableName">打印的表名称</param>
|
|
/// <param name="printKey">打印KEY值</param>
|
|
/// <returns></returns>
|
|
public static int GetPrintNum(string printTableName, string printKey)
|
|
{
|
|
string sql = " SELECT dbo.ZHC_GetPrintCount('{0}','{1}','{2}')";
|
|
sql = string.Format(sql, AppConfig.WorkPointCode, printTableName, printKey);
|
|
object obj = DBHelper.ExecuteScalar(AppConfig.FrameConnectString, CommandType.Text, sql);
|
|
return Convert.ToInt32(obj);
|
|
}
|
|
|
|
#endregion
|
|
public static Dictionary<string, string> GetDataBaseNames()
|
|
{
|
|
|
|
Dictionary<string, string> retDic = new Dictionary<string, string>();
|
|
string sql = @"SELECT '[DB.'+DBSourceName+']' AS [Key],DBSourceName,DBIpAddress,DBName,DBUser,DBPwd
|
|
FROM dbo.Sys_DataBase";
|
|
DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, sql).Tables[0];
|
|
foreach (DataRow dr in data.Rows)
|
|
{
|
|
string key = dr["Key"].ToString();
|
|
if (!retDic.ContainsKey(key))
|
|
{
|
|
|
|
retDic.Add(key, dr["DBName"].ToString());
|
|
}
|
|
|
|
}
|
|
return retDic;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 比如您设置设置的数据源名为ERP 那么您的key 就是[DB.ERP]
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public static string GetDataBaseConnectStringByKey(string key)
|
|
{
|
|
Dictionary<string, string> DIC = GetDataBaseConnectString();
|
|
if (DIC.ContainsKey(key))
|
|
{
|
|
return DIC[key];
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
|
|
}
|
|
private static Dictionary<string, string> GetDataBaseConnectString()
|
|
{
|
|
Dictionary<string, string> retDic = new Dictionary<string, string>();
|
|
string sql = @"SELECT '[DB.'+DBSourceName+']' AS [Key],DBSourceName,DBIpAddress,DBName,DBUser,DBPwd
|
|
FROM dbo.Sys_DataBase where WorkCode='{0}'";
|
|
sql = string.Format(sql, AppConfig.WorkPointCode);
|
|
DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, sql).Tables[0];
|
|
foreach (DataRow dr in data.Rows)
|
|
{
|
|
string key = dr["Key"].ToString();
|
|
string foramtString = "Data Source={0};Database={1};Uid={2};Pwd={3};";
|
|
if (!retDic.ContainsKey(key))
|
|
{
|
|
string pwd = dr["DBPwd"].ToString();
|
|
pwd = FromMd5(pwd);
|
|
string dsql = string.Format(foramtString, new object[] { dr["DBIpAddress"], dr["DBName"], dr["DBUser"], pwd });
|
|
retDic.Add(key, dsql);
|
|
}
|
|
|
|
}
|
|
return retDic;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static DBLinkClass GetDataBaseClass(string key)
|
|
{
|
|
try
|
|
{
|
|
Dictionary<string, string> retDic = new Dictionary<string, string>();
|
|
string sql = @"SELECT '[DB.'+DBSourceName+']' AS [Key],DBSourceName,DBIpAddress,DBName,DBUser,DBPwd
|
|
FROM dbo.Sys_DataBase where WorkCode='{0}'";
|
|
sql = string.Format(sql, AppConfig.WorkPointCode);
|
|
DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, sql).Tables[0];
|
|
foreach (DataRow dr in data.Rows)
|
|
{
|
|
if (key == dr["Key"].ToString())
|
|
{
|
|
DBLinkClass item = new DBLinkClass();
|
|
|
|
string pwd = dr["DBPwd"].ToString();
|
|
pwd = FromMd5(pwd);
|
|
item.DBIpAddress = dr["DBIpAddress"].ToString();
|
|
item.DBName = dr["DBName"].ToString();
|
|
item.DBUser = dr["DBUser"].ToString();
|
|
item.DBPwd = pwd;
|
|
return item;
|
|
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
}
|
|
#region 分页
|
|
public static DataTable GetPageDataByDb(string tablename, string pkey, int pagesize, int pageindex, int rowcount)
|
|
{
|
|
string sql = "EXEC Proc_GetPage '{0}','{1}','',{2},{3},'{1}',0,'*',{4}";
|
|
sql = string.Format(sql, tablename, pkey, pagesize, pageindex, rowcount);
|
|
DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, sql).Tables[0];
|
|
return data;
|
|
}
|
|
public static void DropTemTable(string tempTableName)
|
|
{
|
|
if (!string.IsNullOrEmpty(tempTableName))
|
|
{
|
|
string dropSql = @"IF EXISTS ( SELECT *
|
|
FROM dbo.SysObjects
|
|
WHERE ID = OBJECT_ID(N'[" + tempTableName + "]') ) BEGIN drop table " + tempTableName + " END";
|
|
DBHelper.ExecuteNonQuery(AppConfig.FrameConnectString, CommandType.Text, dropSql);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 创建临时表
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
public static string InsertTempTable(DataTable data, string _tempTableName)
|
|
{
|
|
try
|
|
{
|
|
|
|
if (_tempTableName != "")
|
|
{
|
|
string dropSql = @"IF EXISTS ( SELECT *
|
|
FROM dbo.SysObjects
|
|
WHERE ID = OBJECT_ID(N'[" + _tempTableName + "]') ) BEGIN drop table " + _tempTableName + " END";
|
|
DBHelper.ExecuteNonQuery(AppConfig.FrameConnectString, CommandType.Text, dropSql);
|
|
}
|
|
|
|
_tempTableName = "TEMP_" + AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString("yyyyMMddHHmmss") + "_" + Guid.NewGuid().ToString().Replace("-", "");
|
|
string sql = @"IF not EXISTS ( SELECT * FROM dbo.SysObjects WHERE ID = OBJECT_ID(N'[" + _tempTableName + "]') ) BEGIN CREATE TABLE " + _tempTableName + "(";
|
|
foreach (DataColumn dc in data.Columns)
|
|
{
|
|
if (dc.ColumnName.ToLower() == "pagerowindex")
|
|
{
|
|
string filedCol = dc.ColumnName + " int IDENTITY(1,1) PRIMARY KEY,";
|
|
sql += filedCol;
|
|
|
|
}
|
|
else
|
|
{
|
|
if (dc.DataType == typeof(int))
|
|
{
|
|
string filedCol = dc.ColumnName + " int,";
|
|
sql += filedCol;
|
|
}
|
|
|
|
else if (dc.DataType == typeof(decimal))
|
|
{
|
|
string filedCol = dc.ColumnName + " decimal(18,6),";
|
|
sql += filedCol;
|
|
}
|
|
|
|
else if (dc.DataType == typeof(double))
|
|
{
|
|
string filedCol = dc.ColumnName + " float,";
|
|
sql += filedCol;
|
|
}
|
|
|
|
else if (dc.DataType == typeof(DateTime))
|
|
{
|
|
string filedCol = dc.ColumnName + " datetime,";
|
|
sql += filedCol;
|
|
}
|
|
else if (dc.DataType == typeof(string))
|
|
{
|
|
string filedCol = dc.ColumnName + " nvarchar(2000),";
|
|
sql += filedCol;
|
|
}
|
|
|
|
else if (dc.DataType == typeof(bool))
|
|
{
|
|
string filedCol = dc.ColumnName + " bit,";
|
|
sql += filedCol;
|
|
}
|
|
else
|
|
{
|
|
string filedCol = dc.ColumnName + " nvarchar(2000),";
|
|
sql += filedCol;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
sql = sql.Substring(0, sql.Length - 1) + ") END";
|
|
DBHelper.ExecuteNonQuery(AppConfig.FrameConnectString, CommandType.Text, sql);
|
|
|
|
return _tempTableName;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
|
|
public class DBLinkClass
|
|
{
|
|
public string DBIpAddress { get; set; }
|
|
public string DBName { get; set; }
|
|
public string DBUser { get; set; }
|
|
public string DBPwd { get; set; }
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|