| using System; | 
| using System.Collections.Generic; | 
| using System.Text; | 
| using System.Data; | 
| using System.Windows.Forms; | 
| using System.Drawing; | 
| using System.Data.SqlClient; | 
| using System.Net.Sockets; | 
| using System.Net; | 
|   | 
| namespace Pub_Class | 
| { | 
|     public class ClsPub | 
|     { | 
|         //public static string HTextBox = "HXErp_Test.ini"; | 
|         public static string HTextBox = "HXErp.ini"; | 
|         public static string HUrl_CLD = "http://122.227.128.123:8090/k3cloud/"; | 
|         public static string HdbID_CLD = "5b3711f4fe3fa5"; | 
|         public static string HUserName_CLD = "测试1"; | 
|         public static string HPsd_CLD = "111111"; | 
|         public static string HWEBSUrl_CLD = "http://localhost/SafeWell_Web/WebService1.asmx"; | 
|   | 
|         public static string sCLOUDUrl = ""; | 
|         public static string sCLOUDAcc = ""; | 
|         public static string sCLOUDUseName = ""; | 
|         public static string sCLOUDPsd = ""; | 
|   | 
|         public static Int64 HOrgID = 0;//组织内码 | 
|         public static string HOrgNumber = ""; //组织代码 | 
|         public static string HOrgName = ""; //组织名称 | 
|         public static Int64 HORGANIZATIONSID = 0; | 
|         public static string HORGANIZATIONSNO = ""; | 
|         public static string HDataCenterID = ""; | 
|         public static string IPAddress; | 
|         public static string ComputerName; | 
|         public static string VersionNew; | 
|         public static string VersionOld; | 
|         public static string VersionNum; | 
|         public static string CurUserName=""; | 
|         public static string CurUserID; | 
|         public static string sExeReturnInfo; | 
|         public static string AppPath; | 
|         public static string AccNumber;//帐套代码 | 
|         public static string AccName;//帐套名称 | 
|         public static string CompName;//客户公司名称 | 
|         public static int CurYear; | 
|         public static int CurPeriod; | 
|         public static Color EditColor = Color.White; | 
|         public static Color ViewColor = Color.WhiteSmoke; | 
|         public static int CBCurYear; | 
|         public static int CBCurPeriod; | 
|         public static int XFCurYear; | 
|         public static int XFCurPeriod; | 
|         public static int KQCurYear; | 
|         public static int KQCurPeriod; | 
|         public static DateTime CBCurBDate; | 
|         public static DateTime CBCurEDate; | 
|         public static DateTime XFCurBDate; | 
|         public static DateTime XFCurEDate; | 
|         public static DateTime KQCurBDate; | 
|         public static DateTime KQCurEDate; | 
|   | 
|         public static bool check; | 
|         public static int HCheckStatus; | 
|         public static string sSQLInfo; | 
|         public static string sErrInfo; | 
|   | 
|         public enum Enum_BillStatus : int | 
|         { | 
|             BillStatus_AddNew = 1, | 
|             BillStatus_Modify = 2, | 
|             BillStatus_View = 4, | 
|             BillStatus_UpdatePrice = 8 | 
|         } | 
|   | 
|         public enum Enum_OKTag : int | 
|         { | 
|             OKTag_Cancel = 0, | 
|             OKTag_OK = 1 | 
|         } | 
|   | 
|         public enum Enum_Color : long | 
|         { | 
|             hx_Red = 255, | 
|             hx_Black = 0, | 
|             hx_Write = 16777215, | 
|             hx_Blue = 16711680, | 
|             hx_Green = 65280, | 
|             hx_Yellow = 65535, | 
|             hx_Control = 13425104 | 
|         } | 
|   | 
|         public enum Enum_InputMode : int | 
|         { | 
|             InputMode_View = 0, | 
|             InputMode_AddNew = 1, | 
|             InputMode_Modify = 2, | 
|             InputMode_AddNewGroup = 3, | 
|             InputMode_ModifyGroup = 4 | 
|         } | 
|   | 
|         public enum Enum_InputModeGroup : int | 
|         { | 
|             InputMode_View = 0, | 
|             InputMode_AddNew = 1, | 
|             InputMode_Modify = 2, | 
|         } | 
|           | 
|   | 
|         //获取CLOUD登录信息 | 
|         public static bool GetCLOUDLoginInfo(ref string sExeReturnInfo) | 
|         { | 
|             try | 
|             { | 
|                 AppPath = System.Environment.CurrentDirectory; | 
|                 sCLOUDUrl = ClsIni.ReadIni("CLOUDINFO", "sCLOUDUrl", AppPath + @"\" + HTextBox); | 
|                 sCLOUDAcc = ClsIni.ReadIni("CLOUDINFO", "sCLOUDAcc", AppPath + @"\" + HTextBox); | 
|                 sCLOUDUseName = ClsIni.ReadIni("CLOUDINFO", "sCLOUDUseName", AppPath + @"\" + HTextBox); | 
|                 sCLOUDPsd = ClsIni.ReadIni("CLOUDINFO", "sCLOUDPsd", AppPath + @"\" + HTextBox); | 
|                 if (isStrNull(sCLOUDUrl + sCLOUDAcc + sCLOUDUseName + sCLOUDPsd) == "" || | 
|                     isStrNull(sCLOUDUrl + sCLOUDAcc + sCLOUDUseName + sCLOUDPsd).Contains("没有找到") == true) | 
|                 { | 
|                     sExeReturnInfo = "读取CLOUD配置文件为空! 网址:" + isStrNull(sCLOUDUrl) + "  ; 账套:" + isStrNull(sCLOUDAcc) + " ; 用户:" | 
|                         + isStrNull(sCLOUDUseName) + " ; 密码:" + isStrNull(sCLOUDPsd) + "  文件地址:" + isStrNull(AppPath); | 
|                     return false; | 
|                 } | 
|                 else | 
|                 { | 
|                     return true; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 sExeReturnInfo = "读取CLOUD配置文件失败!网址:" + isStrNull(sCLOUDUrl) + "  ; 账套:" + isStrNull(sCLOUDAcc) + " ; 用户:" | 
|                         + isStrNull(sCLOUDUseName) + " ; 密码:" + isStrNull(sCLOUDPsd) + "  文件地址:" + isStrNull(AppPath) + e.Message; | 
|                 return false; | 
|             } | 
|   | 
|         } | 
|   | 
|   | 
|         //检验 最新版本 | 
|         public static bool CheckUpdate() | 
|         { | 
|              | 
|             DataSet oDs = new DataSet(); | 
|             ClsSqlHelperMaster oCn = new ClsSqlHelperMaster(); | 
|             string LastNumber1 = ""; | 
|             string LastNumber2 = ""; | 
|             string BbNumber = ""; | 
|             string sTableName = ""; | 
|             //得到更新表 | 
|             sTableName = ClsIni.ReadIni("UpDateCounts", "sTableName", ClsPub.AppPath + @"\" + "UpDatePrj.ini"); | 
|             if (sTableName == "没有找到!" || sTableName == "") | 
|             { | 
|                 sTableName = "HX_Update"; | 
|             } | 
|             //得到最新版本 | 
|             try | 
|             { | 
|                 oDs = oCn.RunProcReturn("select top 1 * from " + sTableName + " order by FItemID", sTableName); | 
|                 if (oDs == null || oDs.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     return false; | 
|                 } | 
|                 else | 
|                 { | 
|                     LastNumber1 = oDs.Tables[0].Rows[0]["FNumber"].ToString().Trim(); | 
|                     VersionNew = LastNumber1; | 
|                 } | 
|                 //得到本地版本 | 
|                 LastNumber2 = ClsIni.ReadIni("UpDateCounts", "LastUpdateID", ClsPub.AppPath + @"\" + "UpDatePrj.ini"); | 
|                 VersionOld = LastNumber2; | 
|                 if (LastNumber2 == "没有找到!") | 
|                 { | 
|                     return false; | 
|                 } | 
|                 if (LastNumber2.Trim().ToUpper() == LastNumber1.Trim().ToUpper()) | 
|                 { | 
|                     return false; | 
|                 } | 
|                 return true; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 throw (e); | 
|             } | 
|              | 
|         } | 
|         // | 
|         | 
|   | 
|         //得到列标识 | 
|         public static int Fun_GetCol(DataGridView oGrd, string KeyItem) | 
|         { | 
|             for (int c = 0; c < oGrd.ColumnCount; c++) | 
|             { | 
|                 if (ClsPub.isStrNull(oGrd.Columns[c].HeaderText).ToUpper().Trim() == KeyItem.Trim().ToUpper()) | 
|                 { | 
|                     return c; | 
|                 } | 
|             } | 
|             return 0; | 
|         } | 
|   | 
|         //得到列标识 | 
|         public static int Fun_GetCol_New(DataGridView oGrd, string KeyItem) | 
|         { | 
|             for (int c = 0; c < oGrd.ColumnCount; c++) | 
|             { | 
|                 if (ClsPub.isStrNull(oGrd.Columns[c].HeaderText).ToUpper().Trim() == KeyItem.Trim().ToUpper()) | 
|                 { | 
|                     return c; | 
|                 } | 
|             } | 
|             return -1; | 
|         } | 
|   | 
|         //得到组织内码根据组织名称 | 
|         public static Int64 get_ORGANIZATIONSIDByName(string HDataCenterName) | 
|         { | 
|             try | 
|             { | 
|                 ClsSqlHelper oCN = new ClsSqlHelper(); | 
|                 DataSet ds = oCN.RunProcReturn("select HItemID from h_v_CLD_ORGANIZATIONSList where Hname='" + HDataCenterName + "'", "h_v_CLD_ORGANIZATIONSList"); | 
|                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     return -1; | 
|                 } | 
|                 else | 
|                 { | 
|                     return  ClsPub.isLong(ds.Tables[0].Rows[0]["HItemID"]); | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return -1; | 
|             } | 
|         } | 
|   | 
|         //得到组织编码根据组织名称 | 
|         public static string get_ORGANIZATIONSNOByName(string HDataCenterName) | 
|         { | 
|             try | 
|             { | 
|                 ClsSqlHelper oCN = new ClsSqlHelper(); | 
|                 DataSet ds = oCN.RunProcReturn("select HNumber from h_v_CLD_ORGANIZATIONSList where Hname='" + HDataCenterName + "'", "h_v_CLD_ORGANIZATIONSList"); | 
|                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     return ""; | 
|                 } | 
|                 else | 
|                 { | 
|                     return  ClsPub.isStrNull(ds.Tables[0].Rows[0]["HNumber"]); | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return ""; | 
|             } | 
|         } | 
|   | 
|         //获取组织列表 | 
|         public static DataSet get_ORGANIZATIONSList() | 
|         { | 
|             try | 
|             { | 
|                 ClsSqlHelper oCN = new ClsSqlHelper(); | 
|                 return oCN.RunProcReturn("select * from h_v_CLD_ORGANIZATIONSList", "h_v_CLD_ORGANIZATIONSList"); | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return null; | 
|             } | 
|         } | 
|   | 
|         //得到会计年份根据日期 | 
|         public static bool Sub_GetPeriodByDate(string sDate, ref int sYear, ref int sPeriod) | 
|         { | 
|             DataSet Ds = new DataSet(); | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select  HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where convert(varchar(10),HBeginDate,120)<='" + sDate + "' and convert(varchar(10),HEndDate,120)>='" + sDate + "'", "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return false; | 
|             } | 
|             else | 
|             { | 
|                 sYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString()); | 
|                 sPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString()); | 
|                 return true; | 
|             } | 
|         } | 
|   | 
|         //得到工资 会计年份根据日期 | 
|         public static bool Sub_GetPeriodByDate_Pay(string sDate, ref int sYear, ref int sPeriod) | 
|         { | 
|             DataSet Ds = new DataSet(); | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select  HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where convert(varchar(10),HBeginDate,120)<='" + sDate + "' and convert(varchar(10),HEndDate,120)>='" + sDate + "'", "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return false; | 
|             } | 
|             else | 
|             { | 
|                 sYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString()); | 
|                 sPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString()); | 
|                 return true; | 
|             } | 
|         } | 
|   | 
|   | 
|         //得到K3会计年份根据日期 | 
|         public static bool Sub_GetPeriodByDateK3(string sDate, ref int sYear, ref int sPeriod) | 
|         { | 
|             DataSet Ds; | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select  HYear,HPeriod,HBeginDate,HEndDate from h_v_K3_AcCountPeriod where convert(varchar(10),HBeginDate,120)<='" + sDate + "' and convert(varchar(10),HEndDate,120)>='" + sDate + "'", "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return false; | 
|             } | 
|             else | 
|             { | 
|                 sYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString()); | 
|                 sPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString()); | 
|                 return true; | 
|             } | 
|         } | 
|   | 
|         //得到当前会计年份  | 
|         public static bool Sub_GetCurPeriod(ref int CurYear,ref int CurPeriod) | 
|         { | 
|             DataSet Ds = new DataSet(); | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return false; | 
|             } | 
|             else | 
|             { | 
|                 CurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString()); | 
|                 CurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString()); | 
|                 return true; | 
|             } | 
|         } | 
|   | 
|         //得到工资 当前会计年份  | 
|         public static bool Sub_GetCurPeriod_Pay(ref int CurYear, ref int CurPeriod) | 
|         { | 
|             DataSet Ds = new DataSet(); | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return false; | 
|             } | 
|             else | 
|             { | 
|                 CurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString()); | 
|                 CurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString()); | 
|                 return true; | 
|             } | 
|         } | 
|   | 
|         //得到最大单据号 | 
|         public static string CreateBillCode(string BillCode, ref string sReturn, bool Add) | 
|         { | 
|             Int64 BillCodeMode; | 
|             string Profix; | 
|             Int64 Glida; | 
|             Int32 CodeLen; | 
|             string sBillNo = ""; | 
|             char c = Convert.ToChar("0"); | 
|             string sKjYear = DateTime.Today.Year.ToString(); | 
|             string sPeriod = DateTime.Today.Month.ToString(); | 
|             string sDay = DateTime.Today.Day.ToString(); | 
|             //得到单据号表 信息 | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             DataSet Ds = new DataSet(); | 
|             Ds = oCn.RunProcReturn("Select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber"); | 
|             if (Ds.Tables[0].Rows.Count != 0) | 
|             { | 
|                 BillCodeMode = ClsPub.isLong(Ds.Tables[0].Rows[0]["BillCodeMode"].ToString()); | 
|                 Profix = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Profix"].ToString()); | 
|                 Glida = ClsPub.isLong(Ds.Tables[0].Rows[0]["Glida"].ToString()); | 
|                 CodeLen = ClsPub.isInt(Ds.Tables[0].Rows[0]["CodeLen"].ToString()); | 
|             } | 
|             else | 
|             { | 
|                 return ""; | 
|             } | 
|             // | 
|             string sStr; | 
|             switch (BillCodeMode) | 
|             { | 
|                 case 0: | 
|                     switch (Glida) | 
|                     { | 
|                         case 0://纯流水号 | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "'", "Gy_MaxNum"); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = Profix.Trim() + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_MaxNum(BillCode,NowNumber) values('" + BillCode.Trim() + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sStr + 1; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "'"); | 
|                             } | 
|                             return sBillNo; | 
|   | 
|                         case 1://根据 YY年+MM月 日 + 流水号  生成单据号 (日 采用了 仓库的字段) | 
|                             sKjYear = sKjYear.Substring(2, 2); | 
|                             sPeriod = "0" + sPeriod; | 
|                             sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2); | 
|                             sDay = ""; | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum"); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = Profix.Trim() + sKjYear +  sPeriod  +  sDay  + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sKjYear +  sPeriod +  sDay + sStr + "1"; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'"); | 
|                             } | 
|                             return sBillNo; | 
|                         case 2:      //根据年+月+日  生成单据号 | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum"); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = Profix.Trim() + sKjYear + ClsPub.isStrNull(("0" + sPeriod)).Substring(ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + ClsPub.isStrNull(("0" + sDay)).Substring(ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sKjYear + ClsPub.isStrNull(("0" + sPeriod)).Substring(ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + ClsPub.isStrNull(("0" + sDay)).Substring(ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + 1; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'"); | 
|                             } | 
|                             return sBillNo; | 
|                         case 3: //根据 乔一 (S + 年(23)+五位流水号)实例:S2300001 | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''", "Gy_MaxNum"); | 
|                             sKjYear = sKjYear.Substring(2, 2); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 Profix = Profix.Substring(0, 1); | 
|                                 sBillNo = Profix.Trim() + sKjYear + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sKjYear + sStr + 1; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''"); | 
|                             } | 
|                             return sBillNo; | 
|                         case 4: //根据 乔一 工序流转卡号改成年+月+四位流水号(23050001) | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''", "Gy_MaxNum"); | 
|                             sKjYear = sKjYear.Substring(2, 2); | 
|                             sPeriod = "0" + sPeriod; | 
|                             sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = sKjYear + sPeriod + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)"); | 
|                                 sBillNo = sKjYear + sPeriod + sStr + 1; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='0'  and whcode=''"); | 
|                             } | 
|                             return sBillNo; | 
|                         default: | 
|                             return sBillNo; | 
|   | 
|                     } | 
|   | 
|                 case 1: | 
|                     return sBillNo; | 
|   | 
|                 default: | 
|                     return sBillNo; | 
|   | 
|             } | 
|             oCn.CnClose(); | 
|             oCn.CnDispose(); | 
|             oCn = null; | 
|         } | 
|   | 
|         //得到最大单据号 | 
|         public static string CreateBillCode(string BillCode,string HOrgNumber,Int64 HOrgID,string HWhNumber, ref string sReturn, bool Add) | 
|         { | 
|             Int64 BillCodeMode; | 
|             string Profix; | 
|             Int64 Glida; | 
|             Int32 CodeLen; | 
|             string sBillNo = ""; | 
|             char c = Convert.ToChar("0"); | 
|             string sKjYear = DateTime.Today.Year.ToString(); | 
|             string sPeriod = DateTime.Today.Month.ToString(); | 
|             string sDay = DateTime.Today.Day.ToString(); | 
|             //得到单据号表 信息 | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             DataSet Ds = new DataSet(); | 
|             Ds = oCn.RunProcReturn("Select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber"); | 
|             if (Ds.Tables[0].Rows.Count != 0) | 
|             { | 
|                 BillCodeMode = ClsPub.isLong(Ds.Tables[0].Rows[0]["BillCodeMode"].ToString()); | 
|                 Profix = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Profix"].ToString()); | 
|                 Glida = ClsPub.isLong(Ds.Tables[0].Rows[0]["Glida"].ToString()); | 
|                 CodeLen = ClsPub.isInt(Ds.Tables[0].Rows[0]["CodeLen"].ToString()); | 
|             } | 
|             else | 
|             { | 
|                 return ""; | 
|             } | 
|             // | 
|             string sStr; | 
|             switch (BillCodeMode) | 
|             { | 
|                 case 0: | 
|                     switch (Glida) | 
|                     { | 
|                         case 0://纯流水号 | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "'", "Gy_MaxNum"); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = Profix.Trim() + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_MaxNum(BillCode,NowNumber) values('" + BillCode.Trim() + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sStr + 1; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "'"); | 
|                             } | 
|                             return sBillNo; | 
|   | 
|                         case 1://根据 YY年+MM月 日 + 流水号  生成单据号 (日 采用了 仓库的字段) | 
|                             sKjYear = sKjYear.Substring(2, 2); | 
|                             sPeriod = "0" + sPeriod; | 
|                             sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2); | 
|                             sDay = ""; | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum"); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + "1"; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'"); | 
|                             } | 
|                             return sBillNo; | 
|                         case 2:      //根据年+月+日  生成单据号 (这功能 好像是作废了) | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'", "Gy_MaxNum"); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = Profix.Trim() + sKjYear + ClsPub.isStrNull(("0" + sPeriod)).Substring(ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + ClsPub.isStrNull(("0" + sDay)).Substring(ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + sDay + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sKjYear + ClsPub.isStrNull(("0" + sPeriod)).Substring(ClsPub.isStrNull(("0" + sPeriod)).Length - 2, 2) + ClsPub.isStrNull(("0" + sDay)).Substring(ClsPub.isStrNull(("0" + sDay)).Length - 2, 2) + sStr + 1; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + sDay + "'"); | 
|                             } | 
|                             return sBillNo; | 
|                         case 3://根据 前缀+组织+ YY年+MM月   + 流水号  生成单据号  (组织 采用了 仓库的字段) | 
|                             sKjYear = sKjYear.Substring(2, 2); | 
|                             sPeriod = "0" + sPeriod; | 
|                             sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2); | 
|                              | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + HOrgNumber + "'", "Gy_MaxNum"); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = Profix.Trim() + HOrgNumber + sKjYear + sPeriod  + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_Maxnum(BillCode,Kjyear,Period,whcode,NowNumber)  values('" + BillCode.Trim() + "','" + sKjYear + "','" + sPeriod + "','" + HOrgNumber + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sKjYear + sPeriod + sDay + sStr + "1"; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "' and KjYear='" + sKjYear + "' and Period='" + sPeriod + "' and whcode='" + HOrgNumber + "'"); | 
|                             } | 
|                             return sBillNo; | 
|                         default: | 
|                             return sBillNo; | 
|   | 
|                     } | 
|   | 
|                 case 1: | 
|                     return sBillNo; | 
|   | 
|                 default: | 
|                     return sBillNo; | 
|   | 
|             } | 
|             oCn.CnClose(); | 
|             oCn.CnDispose(); | 
|             oCn = null; | 
|         } | 
|   | 
|   | 
|         //得到最大单据号2 | 
|         public static string CreateBillCode(string BillCode, ref string sReturn, bool Add,ClsSqlHelper oCn) | 
|         { | 
|             Int64 BillCodeMode; | 
|             string Profix; | 
|             Int64 Glida; | 
|             Int32 CodeLen; | 
|             string sBillNo = ""; | 
|             char c = Convert.ToChar("0"); | 
|             //得到单据号表 信息  | 
|             DataSet Ds = new DataSet(); | 
|             Ds = oCn.RunProcReturn("Select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber"); | 
|             if (Ds.Tables[0].Rows.Count != 0) | 
|             { | 
|                 BillCodeMode = ClsPub.isLong(Ds.Tables[0].Rows[0]["BillCodeMode"].ToString()); | 
|                 Profix = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Profix"].ToString()); | 
|                 Glida = ClsPub.isLong(Ds.Tables[0].Rows[0]["Glida"].ToString()); | 
|                 CodeLen = ClsPub.isInt(Ds.Tables[0].Rows[0]["CodeLen"].ToString()); | 
|             } | 
|             else | 
|             { | 
|                 return ""; | 
|             } | 
|             // | 
|             string sStr; | 
|             switch (BillCodeMode) | 
|             { | 
|                 case 0: | 
|                     switch (Glida) | 
|                     { | 
|                         case 0: | 
|                             Ds = oCn.RunProcReturn("Select * from Gy_MaxNum where BillCode='" + BillCode.Trim() + "'", "Gy_MaxNum"); | 
|                             if (Ds.Tables[0].Rows.Count != 0) | 
|                             { | 
|                                 sStr = new string(c, CodeLen - (Ds.Tables[0].Rows[0]["NowNumBer"].ToString()).Length); | 
|                                 sBillNo = Profix.Trim() + sStr + Ds.Tables[0].Rows[0]["NowNumBer"].ToString().Trim(); | 
|                             } | 
|                             else //插入新记录 | 
|                             { | 
|                                 sStr = new string(c, CodeLen - 1); | 
|                                 oCn.RunProc("insert into Gy_MaxNum(BillCode,NowNumber) values('" + BillCode.Trim() + "',1)"); | 
|                                 sBillNo = Profix.Trim() + sStr + 1; | 
|                             } | 
|                             if (Add == true) | 
|                             { | 
|                                 oCn.RunProc("update Gy_Maxnum set NowNumBer=NowNumBer+1 where BillCode='" + BillCode.Trim() + "'"); | 
|                             } | 
|                             return sBillNo; | 
|   | 
|                         case 1: | 
|                             return sBillNo; | 
|   | 
|                         case 2: | 
|                             return sBillNo; | 
|   | 
|                         default: | 
|                             return sBillNo; | 
|   | 
|                     } | 
|   | 
|                 case 1: | 
|                     return sBillNo; | 
|   | 
|                 default: | 
|                     return sBillNo; | 
|   | 
|             } | 
|   | 
|         } | 
|   | 
|   | 
|         //得到最大单据号 存储过程 | 
|         public static string CreateBillCode_Prod(string BillCode, ref string sReturn, bool Add) | 
|         { | 
|             try | 
|             { | 
|                 string BillType = ""; | 
|                 DataSet Ds; | 
|                 ClsSqlHelper oCn = new ClsSqlHelper(); | 
|                 string  sBIllNO; | 
|                 Ds = oCn.RunProcReturn("exec h_p_Xt_GetMaxBillNo '" + BillCode + "'", "h_p_Xt_GetMaxBillNo"); | 
|                 if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     sBIllNO = "ERROR"; | 
|                 } | 
|                 else | 
|                 { | 
|                     sBIllNO = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillNo"]); | 
|                 } | 
|                 oCn.CnClose(); | 
|                 oCn.CnDispose(); | 
|                 oCn = null; | 
|                 Ds = null; | 
|                 return sBIllNO; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return "ERROR"; | 
|             } | 
|         } | 
|   | 
|         //得到最大HINTERID 存储过程 | 
|         public static Int64 CreateBillID_Prod(string BillCode, ref string sReturn) | 
|         { | 
|             try | 
|             { | 
|                 string BillType = ""; | 
|                 DataSet Ds; | 
|                 ClsSqlHelper oCn = new ClsSqlHelper(); | 
|                 Int64 lID; | 
|                 Ds = oCn.RunProcReturn("exec h_p_Xt_GetMaxBillID '" + BillCode + "'", "h_p_Xt_GetMaxBillID"); | 
|                 if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     lID = -1; | 
|                 } | 
|                 else | 
|                 { | 
|                     lID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HBillNo"]); | 
|                 } | 
|                 oCn.CnClose(); | 
|                 oCn.CnDispose(); | 
|                 oCn = null; | 
|                 Ds = null; | 
|                 return lID; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return -2; | 
|             } | 
|         } | 
|   | 
|         //得到最大单据号 存储过程 | 
|         public static string CreateBillCode_SRMProd(string BillCode, ref string sReturn, bool Add) | 
|         { | 
|             try | 
|             { | 
|                 string BillType = ""; | 
|                 DataSet Ds; | 
|                 ClsSqlHelper_SRM oCn = new ClsSqlHelper_SRM(); | 
|                 string sBIllNO; | 
|                 Ds = oCn.RunProcReturn("exec h_p_Xt_GetMaxBillNo '" + BillCode + "'", "h_p_Xt_GetMaxBillNo"); | 
|                 if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     sBIllNO = "ERROR"; | 
|                 } | 
|                 else | 
|                 { | 
|                     sBIllNO = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillNo"]); | 
|                 } | 
|                 oCn.CnClose(); | 
|                 oCn.CnDispose(); | 
|                 oCn = null; | 
|                 Ds = null; | 
|                 return sBIllNO; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return "ERROR"; | 
|             } | 
|         } | 
|   | 
|   | 
|   | 
|         //得到最大HINTERID 存储过程 | 
|         public static Int64 CreateBillID_SRMProd(string BillCode, ref string sReturn) | 
|         { | 
|             try | 
|             { | 
|                 string BillType = ""; | 
|                 DataSet Ds; | 
|                 ClsSqlHelper_SRM oCn = new ClsSqlHelper_SRM(); | 
|                 Int64 lID; | 
|                 Ds = oCn.RunProcReturn("exec h_p_Xt_GetMaxBillID '" + BillCode + "'", "h_p_Xt_GetMaxBillID"); | 
|                 if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     lID = -1; | 
|                 } | 
|                 else | 
|                 { | 
|                     lID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HBillNo"]); | 
|                 } | 
|                 oCn.CnClose(); | 
|                 oCn.CnDispose(); | 
|                 oCn = null; | 
|                 Ds = null; | 
|                 return lID; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return -2; | 
|             } | 
|         } | 
|   | 
|         //得到最大HINTERID | 
|         public static Int64 CreateBillID(string BillCode, ref string sReturn) | 
|         { | 
|             string BillType = ""; | 
|             DataSet Ds; | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Int64 lID; | 
|             Ds = oCn.RunProcReturn("select * from Gy_BillNumber with (nolock) where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber"); | 
|             if (Ds.Tables[0].Rows.Count != 0) | 
|             { | 
|                 lID = ClsPub.isLong(Ds.Tables[0].Rows[0]["IDNow"].ToString()); | 
|                 BillType = Ds.Tables[0].Rows[0]["BillType"].ToString().Trim(); | 
|             } | 
|             else | 
|             { | 
|                 lID = 0; | 
|             } | 
|             //同类型单据 自增1 | 
|             if (BillType.Trim() != "") | 
|             { | 
|                 oCn.RunProc("update Gy_BillNumber set IDNow=IDNow+1 where BillType='" + BillType.Trim() + "'"); | 
|             } | 
|             oCn.CnClose(); | 
|             oCn.CnDispose(); | 
|             oCn = null; | 
|             Ds = null;  | 
|             return lID; | 
|         } | 
|   | 
|         //得到最大HINTERID | 
|         public static Int64 CreateBillID(string BillCode, ref string sReturn,ClsSqlHelper oCn ) | 
|         { | 
|             string BillType = ""; | 
|             DataSet Ds;  | 
|             Int64 lID; | 
|             Ds = oCn.RunProcReturn("select * from Gy_BillNumber where BillCode='" + BillCode.Trim() + "'", "Gy_BillNumber"); | 
|             if (Ds.Tables[0].Rows.Count != 0) | 
|             { | 
|                 lID = ClsPub.isLong(Ds.Tables[0].Rows[0]["IDNow"].ToString()); | 
|                 BillType = Ds.Tables[0].Rows[0]["BillType"].ToString().Trim(); | 
|             } | 
|             else | 
|             { | 
|                 lID = 0; | 
|             } | 
|             //同类型单据 自增1 | 
|             if (BillType.Trim() != "") | 
|             { | 
|                 oCn.RunProc("update Gy_BillNumber set IDNow=IDNow+1 where BillType='" + BillType.Trim() + "'"); | 
|             } | 
|             Ds = null; | 
|             return lID; | 
|         } | 
|   | 
|   | 
|         //判断是否存在权限,并写入日志 | 
|         public static bool Security_Log(string gnsy, int LogTF, bool Msg,string CurUserName) | 
|         { | 
|             //gnsy 功能索引,模块 | 
|             //usercode 当前用户代码 | 
|             //LogTF 1判断权限并写日志,2只写日志,3只判断权限 | 
|             //Msg 没有权限时 是否提示框 | 
|             string UserID = CurUserName; | 
|             try | 
|             { | 
|                 ClsSqlHelper oCn = new ClsSqlHelper(); | 
|                 DataSet Ds = new DataSet(); | 
|                 DataSet DsUser = new DataSet(); | 
|                 DataSet DsJS = new DataSet();//角色 | 
|                 long ModID = 0; | 
|                 bool HavRight = false; | 
|                 //找到模块权限 | 
|                 Ds = oCn.RunProcReturn("select * from xt_xtgnb where gnsy='" + gnsy.Trim() + "'", "xt_xtgnb"); | 
|                 if (Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     if (Msg == true) | 
|                     { | 
|                         MessageBox.Show("没有找到该功能模块!", "提示"); | 
|                     } | 
|                     return false; | 
|                 } | 
|                 else | 
|                 { | 
|                     ModID = ClsPub.isLong(Ds.Tables[0].Rows[0]["ID"].ToString());  //返回模块 | 
|                 } | 
|                 if (LogTF == 1 || LogTF == 3)//需要判断权限 | 
|                 { | 
|                     //根据用户名称判断权限 | 
|                     DsUser = oCn.RunProcReturn("select ManagerFlag,isnull(AuthorityID,'') AuthorityID,Czybm from gy_czygl where czymc='" + UserID.Trim() + "'", "gy_czygl"); | 
|                     if (DsUser.Tables[0].Rows.Count == 0) | 
|                     { | 
|                         if (Msg == true) | 
|                         { | 
|                             MessageBox.Show("没有找到当前操作员!", "提示"); | 
|                         } | 
|                         return false; | 
|                     } | 
|                     //根据用户名称判断权限 | 
|                     if ((bool)DsUser.Tables[0].Rows[0]["ManagerFlag"])  //是否管理员 | 
|                     { | 
|                         HavRight = true; | 
|                     } | 
|                     else | 
|                     { | 
|                         if (ClsPub.isStrNull(DsUser.Tables[0].Rows[0]["AuthorityID"]).Length > ModID | 
|                             && DsUser.Tables[0].Rows[0]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1") | 
|                         { | 
|                             HavRight = true; | 
|                         } | 
|                         else | 
|                         { | 
|                             //获取用户组  并循环判断权限 | 
|                             //判断角色是否有权限 | 
|                             DsJS = oCn.RunProcReturn("select isnull(AuthorityID,'') AuthorityID from System_UserGroupinfo a inner join System_UserGroup b on a.GroupID=b.GroupID " +  | 
|                                 " Where a.USERID='" + DsUser.Tables[0].Rows[0]["Czybm"].ToString().Trim() + "'", "gy_czygl"); | 
|                             if (DsJS == null) | 
|                             { | 
|                                 HavRight = false; | 
|                             } | 
|                             else | 
|                             { | 
|                                 HavRight = false; | 
|                                 for (int i = 0; i < DsJS.Tables[0].Rows.Count; i++) | 
|                                 { | 
|                                     if (ClsPub.isStrNull(DsJS.Tables[0].Rows[i]["AuthorityID"]).Length > ModID) | 
|                                     { | 
|                                         if (DsJS.Tables[0].Rows[i]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1") | 
|                                         { | 
|                                             HavRight = true; | 
|                                             break; | 
|                                         } | 
|                                     } | 
|                                 } | 
|   | 
|                             }  | 
|                         } | 
|                     } | 
|                     | 
|                     if (HavRight == false) | 
|                     { | 
|                         if (Msg == true) | 
|                         { | 
|                             MessageBox.Show("您没有权限,请与管理员联系!", "提示"); | 
|                         } | 
|                     } | 
|                 } | 
|                 //需要写入日志 | 
|                 if ((LogTF == 1 && HavRight) || LogTF == 2) | 
|                 { | 
|                     Add_Log(Ds.Tables[0].Rows[0]["id"].ToString().Trim(), gnsy +","+ Ds.Tables[0].Rows[0]["gnmc"].ToString().Trim(), CurUserName); | 
|                 } | 
|                 return HavRight; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 if (Msg == true) | 
|                 { | 
|                     MessageBox.Show("判断权限时发现错误,请与管理员联系!", "提示"); | 
|                 } | 
|                 return false; | 
|             } | 
|         } | 
|   | 
|         public static bool Security_Log_second(string gnsy, int LogTF, bool Msg, string CurUserName) | 
|         { | 
|             //gnsy 功能索引,模块 | 
|             //usercode 当前用户代码 | 
|             //LogTF 1判断权限并写日志,2只写日志,3只判断权限 | 
|             //Msg 没有权限时 是否提示框 | 
|             string UserID = CurUserName; | 
|             try | 
|             { | 
|                 ClsSqlHelper oCn = new ClsSqlHelper(); | 
|                 DataSet Ds = new DataSet(); | 
|                 DataSet DsUser = new DataSet(); | 
|                 DataSet DsJS = new DataSet();//角色 | 
|                 long ModID = 0; | 
|                 bool HavRight = false; | 
|                 //找到模块权限 | 
|                 Ds = oCn.RunProcReturn("select * from xt_xtgnb where gnsy='" + gnsy.Trim() + "'", "xt_xtgnb"); | 
|                 if (Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     if (Msg == true) | 
|                     { | 
|                         return false; | 
|                         //MessageBox.Show("没有找到该功能模块!", "提示"); | 
|                     } | 
|                     return false; | 
|                 } | 
|                 else | 
|                 { | 
|                     ModID = ClsPub.isLong(Ds.Tables[0].Rows[0]["ID"].ToString());  //返回模块 | 
|                 } | 
|                 if (LogTF == 1 || LogTF == 3)//需要判断权限 | 
|                 { | 
|                     //根据用户名称判断权限 | 
|                     DsUser = oCn.RunProcReturn("select * from gy_czygl where czymc='" + UserID.Trim() + "'", "gy_czygl"); | 
|                     if (DsUser.Tables[0].Rows.Count == 0) | 
|                     { | 
|                         if (Msg == true) | 
|                         { | 
|                             return false; | 
|                             //MessageBox.Show("没有找到当前操作员!", "提示"); | 
|                         } | 
|                         return false; | 
|                     } | 
|                     //根据用户名称判断权限 | 
|                     if ((bool)DsUser.Tables[0].Rows[0]["ManagerFlag"])  //是否管理员 | 
|                     { | 
|                         HavRight = true; | 
|                     } | 
|                     else | 
|                     { | 
|                         if (DsUser.Tables[0].Rows[0]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1") | 
|                         { | 
|                             HavRight = true; | 
|                         } | 
|                         else | 
|                         { | 
|                             //获取用户组  并循环判断权限 | 
|                             //判断角色是否有权限 | 
|                             DsJS = oCn.RunProcReturn("select isnull(AuthorityID,'') AuthorityID from System_UserGroupinfo a inner join System_UserGroup b on a.GroupID=b.GroupID " + | 
|                                 " Where a.USERID='" + UserID.Trim() + "'", "gy_czygl"); | 
|                             if (DsJS == null) | 
|                             { | 
|                                 HavRight = false; | 
|                             } | 
|                             else | 
|                             { | 
|                                 HavRight = false; | 
|                                 for (int i = 0; i < DsJS.Tables[0].Rows.Count; i++) | 
|                                 { | 
|                                     if (ClsPub.isStrNull(DsJS.Tables[0].Rows[i]["AuthorityID"]).Length > ModID) | 
|                                     { | 
|                                         if (DsJS.Tables[0].Rows[i]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1") | 
|                                         { | 
|                                             HavRight = true; | 
|                                             break; | 
|                                         } | 
|                                     } | 
|                                 } | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|   | 
|                     if (HavRight == false) | 
|                     { | 
|                         if (Msg == true) | 
|                         { | 
|                             return false; | 
|                             //MessageBox.Show("您没有权限,请与管理员联系!", "提示"); | 
|                         } | 
|                     } | 
|                 } | 
|                 //需要写入日志 | 
|                 if ((LogTF == 1 && HavRight) || LogTF == 2) | 
|                 { | 
|                     Add_Log(Ds.Tables[0].Rows[0]["id"].ToString().Trim(), gnsy + "," + Ds.Tables[0].Rows[0]["gnmc"].ToString().Trim(), CurUserName); | 
|                 } | 
|                 return HavRight; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 if (Msg == true) | 
|                 { | 
|                     return false; | 
|                     //MessageBox.Show("判断权限时发现错误,请与管理员联系!", "提示"); | 
|                 } | 
|                 return false; | 
|             } | 
|         } | 
|   | 
|         //判断是都存在权限,并写入日志 | 
|         public static bool Security_Log(string gnsy, int LogTF, bool Msg, string CurUserName, ClsSqlHelper oCn) | 
|         { | 
|             //gnsy 功能索引,模块 | 
|             //usercode 当前用户代码 | 
|             //LogTF 1判断权限并写日志,2只写日志,3只判断权限 | 
|             //Msg 没有权限时 是否提示框 | 
|             string UserID = CurUserName; | 
|             try | 
|             {  | 
|                 DataSet Ds = new DataSet(); | 
|                 DataSet DsUser = new DataSet(); | 
|                 long ModID = 0; | 
|                 bool HavRight = false; | 
|                 Ds = oCn.RunProcReturn("select * from xt_xtgnb where gnsy='" + gnsy.Trim() + "'", "xt_xtgnb"); | 
|                 if (Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     MessageBox.Show("没有找到该功能模块!", "提示"); | 
|                     return false; | 
|                 } | 
|                 else | 
|                 { | 
|                     ModID = ClsPub.isLong(Ds.Tables[0].Rows[0]["ID"].ToString()); | 
|                 } | 
|                 if (LogTF == 1 || LogTF == 3)//需要判断权限 | 
|                 { | 
|                     DsUser = oCn.RunProcReturn("select * from gy_czygl where czymc='" + UserID.Trim() + "'", "gy_czygl"); | 
|                     if (DsUser.Tables[0].Rows.Count == 0) | 
|                     { | 
|                         MessageBox.Show("没有找到当前操作员!", "提示"); | 
|                         return false; | 
|                     } | 
|                     if ((bool)DsUser.Tables[0].Rows[0]["ManagerFlag"])  //是否管理员 | 
|                     { | 
|                         HavRight = true; | 
|                     } | 
|                     else | 
|                     { | 
|                         if (DsUser.Tables[0].Rows[0]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1") | 
|                         { | 
|                             HavRight = true; | 
|                         } | 
|                         else | 
|                         { | 
|                             HavRight = false; | 
|                         } | 
|                     } | 
|                     if (HavRight == false) | 
|                     { | 
|                         if (Msg == true) | 
|                         { | 
|                             MessageBox.Show("您没有权限,请与管理员联系!", "提示"); | 
|                         } | 
|                     } | 
|                 } | 
|                 //需要写入日志 | 
|                 if ((LogTF == 1 && HavRight) || LogTF == 2) | 
|                 { | 
|                     Add_Log(Ds.Tables[0].Rows[0]["id"].ToString().Trim(), gnsy + "," + Ds.Tables[0].Rows[0]["gnmc"].ToString().Trim(), CurUserName); | 
|                 } | 
|                 return HavRight; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 if (Msg == true) | 
|                 { | 
|                     MessageBox.Show("判断权限时发现错误,请与管理员联系!", "提示"); | 
|                 } | 
|                 return false; | 
|             } | 
|         } | 
|   | 
|         //判断是都存在权限,并写入日志 | 
|         public static bool Security_Log2(string gnsy, int LogTF, bool Msg, string CurUserName) | 
|         { | 
|             //gnsy 功能索引,模块 | 
|             //usercode 当前用户代码 | 
|             //LogTF 1判断权限并写日志,2只写日志,3只判断权限 | 
|             //Msg 没有权限时 是否提示框 | 
|             string UserID = CurUserName; | 
|             try | 
|             { | 
|                 ClsSqlHelper oCn = new ClsSqlHelper(); | 
|                 DataSet Ds = new DataSet(); | 
|                 DataSet DsUser = new DataSet(); | 
|                 long ModID = 0; | 
|                 bool HavRight = false; | 
|                 Ds = oCn.RunProcReturn("select * from xt_xtgnb where gnsy='" + gnsy.Trim() + "'", "xt_xtgnb"); | 
|                 if (Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     MessageBox.Show("没有找到该功能模块!", "提示"); | 
|                     return false; | 
|                 } | 
|                 else | 
|                 { | 
|                     ModID = ClsPub.isLong(Ds.Tables[0].Rows[0]["ID"].ToString()); | 
|                 } | 
|                 if (LogTF == 1 || LogTF == 3)//需要判断权限 | 
|                 { | 
|                     DsUser = oCn.RunProcReturn("select * from gy_czygl where czymc='" + UserID.Trim() + "'", "gy_czygl"); | 
|                     if (DsUser.Tables[0].Rows.Count == 0) | 
|                     { | 
|                         MessageBox.Show("没有找到当前操作员!", "提示"); | 
|                         return false; | 
|                     } | 
|                     if ((bool)DsUser.Tables[0].Rows[0]["ManagerFlag"])  //是否管理员 | 
|                     { | 
|                         HavRight = true; | 
|                     } | 
|                     else | 
|                     { | 
|                         if (DsUser.Tables[0].Rows[0]["AuthorityID"].ToString().Trim().Substring((int)ModID - 1, 1) == "1") | 
|                         { | 
|                             HavRight = true; | 
|                         } | 
|                         else | 
|                         { | 
|                             HavRight = false; | 
|                         } | 
|                     } | 
|                     if (HavRight == false) | 
|                     { | 
|                         if (Msg == true) | 
|                         { | 
|                             MessageBox.Show("您没有权限,请与管理员联系!", "提示"); | 
|                         } | 
|                     } | 
|                 } | 
|                 //需要写入日志 | 
|                 if ((LogTF == 1 && HavRight) || LogTF == 2) | 
|                 { | 
|                     Add_Log(Ds.Tables[0].Rows[0]["id"].ToString().Trim(), gnsy + "," + Ds.Tables[0].Rows[0]["gnmc"].ToString().Trim(), CurUserName); | 
|                 } | 
|                 return HavRight; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 if (Msg == true) | 
|                 { | 
|                     MessageBox.Show("判断权限时发现错误,请与管理员联系!", "提示"); | 
|                 } | 
|                 return false; | 
|             } | 
|         } | 
|         //写入日志 | 
|         /// <summary> | 
|         /// 写入日志 | 
|         /// </summary> | 
|         /// <param name="UserID">无用</param> | 
|         /// <param name="WorkList">操作日志</param> | 
|         /// <param name="CurUserName">操作员</param> | 
|         /// <returns></returns> | 
|         public static bool Add_Log(string UserID, string WorkList, string CurUserName) | 
|         { | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             try | 
|             { | 
|                 oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " + | 
|                     "(getdate(),'" + CurUserName + "','" + ComputerName + "','" + WorkList + "','ERP系统','"+IPAddress+"','进入')" | 
|                     ); | 
|                 return true; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("写入日志时发现错误,原因是:" + e.Message); | 
|                 return false; | 
|             } | 
|         } | 
|         //写入日志 | 
|         /// <summary> | 
|         /// 写入日志 | 
|         /// </summary> | 
|         /// <param name="UserID">无用</param> | 
|         /// <param name="WorkList">操作日志</param> | 
|         /// <param name="CurUserName">操作员</param> | 
|         /// <param name="oCn">连接</param> | 
|         /// <returns></returns> | 
|         public static bool Add_Log(string UserID, string WorkList, string CurUserName, ClsSqlHelper oCn) | 
|         {  | 
|             try | 
|             { | 
|                 oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " + | 
|                     "(getdate(),'" + CurUserName + "','" + ComputerName + "','" + WorkList + "','ERP系统','" + IPAddress + "','进入')" | 
|                     ); | 
|                 return true; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("写入日志时发现错误,原因是:" + e.Message); | 
|                 return false; | 
|             } | 
|         } | 
|         //得到会计期间 | 
|         public static string Sub_GetDateByPeriod(int sYear, int sPeriod) | 
|         { | 
|             DataSet Ds = new DataSet(); | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select  HBeginDate,HEndDate from xt_AcCountPeriod where HYear=" + sYear + " and HPeriod=" + sPeriod, "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return ""; | 
|             } | 
|             else | 
|             { | 
|                 return ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"].ToString(), 0) + "," + ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"].ToString(), 0); | 
|             } | 
|         } | 
|         //得到服务器日期 | 
|         public static string GetServerDate(Int64 iType) | 
|         { | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             DataSet Ds = new DataSet(); | 
|             try | 
|             { | 
|                 Ds = oCn.RunProcReturn("Select GetDate() as CurDate", "xt_xtgnb"); | 
|                 switch (iType) | 
|                 { | 
|                     case 0: | 
|                         return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("yyyy-MM-dd"); | 
|                     case 1: | 
|                         return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("HH:mm:ss"); | 
|                     case -1: | 
|                         return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("yyyy-MM-dd HH:mm:ss"); | 
|                     default: | 
|                         return "1900-01-01"; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return "1900-01-01"; | 
|             } | 
|         } | 
|   | 
|         //得到服务器日期 | 
|         public static string GetServerDate(Int64 iType, ClsSqlHelper oCn) | 
|         {  | 
|             DataSet Ds; | 
|             try | 
|             { | 
|                 Ds = oCn.RunProcReturn("Select GetDate() as CurDate", "xt_xtgnb"); | 
|                 switch (iType) | 
|                 { | 
|                     case 0: | 
|                         return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("yyyy-MM-dd"); | 
|                     case 1: | 
|                         return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("hh:mm:ss"); | 
|                     case -1: | 
|                         return Convert.ToDateTime(Ds.Tables[0].Rows[0]["CurDate"]).ToString("yyyy-MM-dd HH:mm:ss"); | 
|                     default: | 
|                         return "1900-01-01"; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return "1900-01-01"; | 
|             } | 
|         } | 
|   | 
|         //根据模块名 返回 网格 信息 | 
|         public static string Fun_GetGridStrByModName(string KeyItem) | 
|         { | 
|             try | 
|             { | 
|                 ClsSqlHelper oCn = new ClsSqlHelper(); | 
|                 DataSet ds; | 
|                 ds = oCn.RunProcReturn("select top 1 HGridString from Xt_grdAlignment where HUserName='" + ClsPub.CurUserName + "' and HModName='" + KeyItem + "'", "Xt_grdAlignment"); | 
|                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     return "没有找到!"; | 
|                 } | 
|                 else | 
|                 { | 
|                     return ClsPub.isStrNull(ds.Tables[0].Rows[0]["HGridString"]); | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return "没有找到!"; | 
|             } | 
|         } | 
|   | 
|         // 读取隐藏列datagridview  并设置 对齐方式 | 
|         /// <summary> | 
|         /// 读取隐藏列datagridview  并设置 对齐方式 | 
|         /// </summary> | 
|         /// <param name="oGrd"></param> | 
|         /// <param name="KeyItem"></param> | 
|         /// <param name="AppPath"></param> | 
|         public static void HideGridView(DataGridView oGrd, string KeyItem, string AppPath) | 
|         { | 
|             int Cols; | 
|             char c = Convert.ToChar(","); | 
|             char s = Convert.ToChar("|"); | 
|             string sStr =ClsPub.Fun_GetGridStrByModName(KeyItem); | 
|             if (sStr != "没有找到!") | 
|             { | 
|                 string[] Col = sStr.Split(c); | 
|                 for (int i = 0; i < Col.Length; i++) | 
|                 { | 
|                     if (i >= oGrd.ColumnCount) | 
|                     { | 
|                         break; | 
|                     } | 
|                     string[] sCol = Col[i].Split(s); | 
|                     if (sCol.Length > 1) | 
|                     { | 
|                         if (ClsPub.isStrNull(sCol[1]) == "1") | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = false;                           //隐藏列 | 
|                         } | 
|                         else | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = true;                           //隐藏列 | 
|                         } | 
|                         //h开头的隐藏 | 
|                         if (oGrd.Columns[ClsPub.isInt(sCol[0])].HeaderText != "") | 
|                         { | 
|                             if (oGrd.Columns[ClsPub.isInt(sCol[0])].HeaderText.Substring(0, 1).ToLower() == "h") | 
|                             { | 
|                                 oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = false; | 
|                             } | 
|                         } | 
|                         else | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = false; | 
|                         } | 
|                     } | 
|                     // | 
|                     if (sCol.Length > 2) | 
|                     { | 
|                         if (ClsPub.isStrNull(sCol[2]) == "L") | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;                           //  | 
|                         } | 
|                         else if (ClsPub.isStrNull(sCol[2]) == "R") | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;    //  | 
|                         } | 
|                         else if (ClsPub.isStrNull(sCol[2]) == "M") | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;    //  | 
|                         } | 
|                         else | 
|                         { | 
|                             //; | 
|                         } | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|   | 
|         // 读取隐藏列datagridview  并设置 对齐方式  从数据库读取 | 
|         public static void HideGridView(DataGridView oGrd, string KeyItem) | 
|         { | 
|   | 
|             int Cols; | 
|             char c = Convert.ToChar(","); | 
|             char s = Convert.ToChar("|"); | 
|             string sStr = ClsIni.ReadIni("GridHide", KeyItem, AppPath + @"\" + "grdWidth.wyini"); | 
|             if (sStr != "没有找到!") | 
|             { | 
|                 string[] Col = sStr.Split(c); | 
|                 for (int i = 0; i < Col.Length; i++) | 
|                 { | 
|                     string[] sCol = Col[i].Split(s); | 
|                     if (sCol.Length > 1) | 
|                     { | 
|                         if (ClsPub.isStrNull(sCol[1]) == "1") | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = false;                           //隐藏列 | 
|                         } | 
|                         else | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].Visible = true;                           //隐藏列 | 
|                         } | 
|                     } | 
|                     // | 
|                     if (sCol.Length > 2) | 
|                     { | 
|                         if (ClsPub.isStrNull(sCol[2]) == "L") | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;                           //  | 
|                         } | 
|                         else if (ClsPub.isStrNull(sCol[2]) == "R") | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;    //  | 
|                         } | 
|                         else if (ClsPub.isStrNull(sCol[2]) == "M") | 
|                         { | 
|                             oGrd.Columns[ClsPub.isInt(sCol[0])].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;    //  | 
|                         } | 
|                         else | 
|                         { | 
|                             //; | 
|                         } | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|   | 
|         // 读取列宽datagridview | 
|         public static void GetGridView(DataGridView oGrd, string KeyItem, string AppPath) | 
|         { | 
|             try | 
|             { | 
|                 if (oGrd.RowCount <= 1) | 
|                 { | 
|                     return; | 
|                 } | 
|                 int Cols; | 
|                 char c = Convert.ToChar(","); | 
|                 string sStr = ClsIni.ReadIni("GridSave", KeyItem, AppPath + @"\" + "grdWidth.wyini"); | 
|                 if (sStr != "没有找到!") | 
|                 { | 
|                     string[] ColWidth = sStr.Split(c); | 
|                     if (oGrd.ColumnCount > ColWidth.Length) | 
|                     { | 
|                         Cols = ColWidth.Length; | 
|                     } | 
|                     else | 
|                     { | 
|                         Cols = oGrd.ColumnCount; | 
|                     } | 
|                     for (int i = 0; i < Cols; i++) | 
|                     { | 
|                         if (ClsPub.isInt(ColWidth[i]) > 500) | 
|                         { | 
|                             oGrd.Columns[i].Width = ClsPub.isInt(ColWidth[i]); | 
|                         } | 
|                         else | 
|                         { | 
|                             oGrd.Columns[i].Width = ClsPub.isInt(ColWidth[i]); | 
|                         } | 
|                     } | 
|                 } | 
|             } | 
|             catch(Exception e) | 
|             { | 
|                 MessageBox.Show("设置列宽失败!" + e.Message); | 
|             } | 
|         } | 
|         //保存列宽 | 
|         public static void SaveGridView(DataGridView oGrd, string KeyItem, string AppPath) | 
|         { | 
|             int i; | 
|             string SaveStr = ""; | 
|             for (i = 0; i <= oGrd.ColumnCount - 1; i++) | 
|             { | 
|                 if (i == 0) | 
|                     SaveStr = oGrd.Columns[i].Width.ToString(); | 
|                 else | 
|                     SaveStr = SaveStr + "," + oGrd.Columns[i].Width.ToString(); | 
|             } | 
|             ClsIni oIni = new ClsIni(); | 
|             if (ClsIni.WriteIni("GridSave", KeyItem, SaveStr, AppPath + @"\" + "grdWidth.wyini")) | 
|                 SaveStr = ""; | 
|         } | 
|         //默认列宽 | 
|         public static void DefaultGridView(DataGridView oGrd) | 
|         { | 
|             for (int i = 0; i <= oGrd.ColumnCount - 1; i++) | 
|             { | 
|                 oGrd.Columns[i].Width = 100; | 
|             } | 
|              | 
|         } | 
|         | 
|         //审核代码合理性 | 
|         public static bool AllowNumber(string sCode) | 
|         { | 
|             sCode = sCode.Trim(); | 
|             if (sCode == "") | 
|             { | 
|                 return true; | 
|             } | 
|             if (sCode.Substring(sCode.Length-1, 1) == ".") | 
|             { | 
|                 return false; | 
|             } | 
|             if (sCode.Substring(0, 1) == ".") | 
|             { | 
|                 return false; | 
|             } | 
|             if (sCode.Contains("..")) | 
|             { | 
|                 return false; | 
|             } | 
|             return true; | 
|         } | 
|         //得到父级 | 
|         public static string GetParentCode(string sCode) | 
|         { | 
|             if (sCode.Contains(".")) | 
|             { | 
|                 for (int i =sCode.Length ; i > 0; i--) | 
|                 { | 
|                     if (sCode.Substring(i-1, 1) == ".") | 
|                     { | 
|                         return sCode.Substring(0, i - 1); | 
|                     } | 
|                 } | 
|                 return ""; | 
|             } | 
|             else | 
|                 return ""; | 
|         } | 
|         //得到短代码 | 
|         public static string GetShortNumber(string sCode) | 
|         { | 
|             if (sCode.Contains(".")) | 
|             { | 
|                 for (int i = sCode.Length; i > 0; i--) | 
|                 { | 
|                     if (sCode.Substring(i - 1, 1) == ".") | 
|                     { | 
|                         return sCode.Substring(i,sCode.Length - i); | 
|                     } | 
|                 } | 
|                 return sCode; | 
|             } | 
|             else | 
|                 return sCode; | 
|         } | 
|         //得到代码等级 | 
|         public static int GetLevel(string sCode) | 
|         { | 
|             return sCode.Length - (sCode.Replace(".", "").Length)+1; | 
|         } | 
|   | 
|         //获取下拉框的 内码 | 
|         public static int GetIDByComboBox(string sCode) | 
|         { | 
|             if (sCode.Trim() == "") | 
|             { | 
|                 return 0; | 
|             } | 
|             if (sCode.Contains("-")) | 
|             { | 
|                 string[] s; | 
|                 s = sCode.Split(Convert.ToChar("-")); | 
|                 return ClsPub.isInt(s[0]); | 
|             } | 
|             else | 
|             { | 
|                 return 0; | 
|             } | 
|         } | 
|   | 
|         //转化GRID中的 布尔型 | 
|         public static string GridToStr(object message) | 
|         { | 
|             try | 
|             { | 
|                 if (Convert.ToString(message) == "-1" || Convert.ToString(message) == "1" || Convert.ToString(message) == "True") | 
|                     return "1"; | 
|                 else | 
|                     return "0"; | 
|   | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return "0"; | 
|             } | 
|         } | 
|   | 
|         //字符转为布尔 | 
|         /// <summary> | 
|         /// 将是或者否转化为TRUE和FALSE | 
|         /// </summary> | 
|         /// <param name="b"></param> | 
|         /// <returns></returns> | 
|         public static bool StringToBool(object b) | 
|         { | 
|             try | 
|             { | 
|                 if (Convert.ToString(b) == "是") | 
|                     return true; | 
|                 else | 
|                     return false; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return false; | 
|             } | 
|         } | 
|   | 
|         //转化GRID中的 布尔型 | 
|         public static bool GridToBool(object message) | 
|         { | 
|             try | 
|             { | 
|                 if (Convert.ToString(message) == "-1" || Convert.ToString(message) == "1" || Convert.ToString(message) == "True") | 
|                     return true; | 
|                 else | 
|                     return false; | 
|   | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return false; | 
|             } | 
|         } | 
|   | 
|         //判断是否是INT64 | 
|         public static Int64 isLong(object message) | 
|         { | 
|             try | 
|             { | 
|                 return Convert.ToInt64(message); | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return 0; | 
|             } | 
|         } | 
|         //判断是否是INT32 | 
|         public static int isInt(object message) | 
|         { | 
|             try | 
|             { | 
|                 return Convert.ToInt16(message); | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return 0; | 
|             } | 
|         } | 
|         //判断是否NULL | 
|         public static string  isStrNull(object message) | 
|         { | 
|             try | 
|             { | 
|                 if (message == null) | 
|                 { | 
|                     return ""; | 
|                 } | 
|                 else | 
|                 { | 
|                     return message.ToString().Trim(); | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return ""; | 
|             } | 
|         } | 
|         //判断是否双精度 | 
|         public static double isDoule(object message) | 
|         { | 
|             try | 
|             { | 
|                 return Convert.ToDouble(message); | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return 0; | 
|             } | 
|         } | 
|         ////判断是否双精度 并返回保留小数 | 
|         public static string isDoule(object message, int n) | 
|         { | 
|             try | 
|             { | 
|                 return Convert.ToDouble(message).ToString("F"+n.ToString()); | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return ""; | 
|             } | 
|         } | 
|         //布尔转为字符 | 
|         public static string BoolToString(object b) | 
|         { | 
|             try | 
|             { | 
|                 if (Convert.ToBoolean(b)) | 
|                     return "1"; | 
|                 else | 
|                     return "0"; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return "0"; | 
|             } | 
|             | 
|         } | 
|         //判断布尔 | 
|         public static bool isBool(object message) | 
|         { | 
|             try | 
|             { | 
|                 return Convert.ToBoolean(message); | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return false; | 
|             } | 
|         } | 
|         //判断是否 单精度 | 
|         public static Single isSingle(object message) | 
|         { | 
|             try | 
|             { | 
|                 return Convert.ToSingle(message); | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return 0; | 
|             } | 
|         } | 
|         //判断2个日期的大小 | 
|         /// <summary> | 
|         /// 比较2个日期的大小 | 
|         /// </summary> | 
|         /// <param name="Date1">日期1</param> | 
|         /// <param name="Date2">日期2</param> | 
|         /// <returns>-1 日期1小于日期2 0 相等 1 日期1大于日期2</returns> | 
|         public static int TwoDateCompare(object Date1,object Date2) | 
|         { | 
|             string Date3 = ClsPub.isDate(Date1, -1); | 
|             string Date4 = ClsPub.isDate(Date2,-1); | 
|             if (DateTime.Parse(Date3) > DateTime.Parse(Date4)) | 
|             { | 
|                 return 1; | 
|             } | 
|             else if (DateTime.Parse(Date3) == DateTime.Parse(Date4)) | 
|             { | 
|                 return 0; | 
|             } | 
|             else | 
|             { | 
|                 return -1; | 
|             } | 
|         } | 
|   | 
|         //判断是否是  | 
|         public static Enum_Color GridToColor(object message) | 
|         { | 
|             try | 
|             { | 
|                 switch (Convert.ToInt64(message)) | 
|                 { | 
|                     case 0: | 
|                         return Enum_Color.hx_Black; | 
|                     case 16711680: | 
|                         return Enum_Color.hx_Blue; | 
|                     case 65280: | 
|                         return Enum_Color.hx_Green; | 
|                     case 255: | 
|                         return Enum_Color.hx_Red; | 
|                     case 16777215: | 
|                         return Enum_Color.hx_Write; | 
|                     case 65535: | 
|                         return Enum_Color.hx_Yellow; | 
|                     case 13425104: | 
|                         return Enum_Color.hx_Control; | 
|                     default: | 
|                         return Enum_Color.hx_Black; | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return Enum_Color.hx_Black; | 
|             } | 
|         } | 
|         //双精度 四舍五入 | 
|         public static double ChinaRound(Single value, int decimals) | 
|         { | 
|             return Math.Round(value, decimals, MidpointRounding.AwayFromZero); | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 返回 日期的字符串 | 
|         /// </summary> | 
|         /// <param name="oVal"></param> | 
|         /// <param name="sType">d日期dt日期时间t时间</param> | 
|         /// <returns></returns> | 
|         public static string DataTimeToStr(object oVal,string sType) | 
|         { | 
|             try | 
|             { | 
|                 DateTime dt; | 
|                 if (sType == "d") | 
|                 { | 
|                     if (oVal == null) | 
|                     { | 
|                         return "1900-01-01" ; | 
|                     } | 
|                     else | 
|                     { | 
|                         dt = Convert.ToDateTime(oVal); | 
|                         return dt.ToShortDateString(); | 
|                     } | 
|                 } | 
|                 else if (sType == "dt") | 
|                 { | 
|                     if (oVal == null) | 
|                     { | 
|                         return  "1900-01-01 00:00:00" ; | 
|                     } | 
|                     else | 
|                     { | 
|                         dt = Convert.ToDateTime(oVal); | 
|                         return dt.ToShortDateString() + " " + dt.ToShortTimeString(); | 
|                     } | 
|                 } | 
|                 else if (sType == "t") | 
|                 { | 
|                     if (oVal == null) | 
|                     { | 
|                         return "00:00:00"; | 
|                     } | 
|                     else | 
|                     { | 
|                         dt = Convert.ToDateTime(oVal); | 
|                         return dt.ToShortTimeString(); | 
|                     } | 
|                 } | 
|                 else | 
|                 { | 
|                     if (oVal == null) | 
|                     { | 
|                         return  "1900-01-01" ; | 
|                     } | 
|                     else | 
|                     { | 
|                         dt = Convert.ToDateTime(oVal); | 
|                         return dt.ToShortDateString(); | 
|                     } | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return  "1900-01-01"; | 
|             } | 
|         } | 
|   | 
|         //判断是否 是日期类型 | 
|         public static DateTime isDate(object oVal) | 
|         { | 
|             DateTime dt; | 
|             if (oVal == null) | 
|             { | 
|                 return Convert.ToDateTime("1900-01-01"); | 
|             } | 
|             try | 
|             { | 
|                 dt = Convert.ToDateTime(oVal); | 
|                 if (dt > Convert.ToDateTime("1900-01-01")) | 
|                 { | 
|                     return Convert.ToDateTime(oVal); | 
|                 } | 
|                 else | 
|                 { | 
|                     return Convert.ToDateTime("1900-01-01"); | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return Convert.ToDateTime("1900-01-01"); | 
|             } | 
|         } | 
|         //判断是否 是日期类型 并按格式返回 | 
|         /// <summary> | 
|         ///  | 
|         /// </summary> | 
|         /// <param name="oVal"></param> | 
|         /// <param name="n">-1 全部 0 日期 1 时间</param> | 
|         /// <returns></returns> | 
|         public static string isDate(object oVal,int n) | 
|         { | 
|             if (oVal == null) | 
|             { | 
|                 if (n == -1) | 
|                 { | 
|                     return Convert.ToDateTime("1900-01-01 00:00:00").ToString("yyyy-MM-dd HH:mm:ss"); | 
|                 } | 
|                 else if (n == 0) | 
|                 { | 
|                     return Convert.ToDateTime("1900-01-01").ToString("yyyy-MM-dd"); | 
|                 } | 
|                 else | 
|                 { | 
|                     return Convert.ToDateTime("1900-01-01 00:00:00").ToString("HH:mm:ss"); | 
|                 } | 
|             } | 
|             try | 
|             { | 
|                 if (n == -1) | 
|                 { | 
|                     return Convert.ToDateTime(oVal).ToString("yyyy-MM-dd HH:mm:ss"); | 
|                 } | 
|                 else if (n == 0) | 
|                 { | 
|                     return Convert.ToDateTime(oVal).ToString("yyyy-MM-dd"); | 
|                 } | 
|                 else | 
|                 { | 
|                     return Convert.ToDateTime(oVal).ToString("HH:mm:ss"); | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 if (n == -1) | 
|                 { | 
|                     return Convert.ToDateTime("1900-01-01 00:00:00").ToString("yyyy-MM-dd hh:mm:ss"); | 
|                 } | 
|                 else if (n == 0) | 
|                 { | 
|                     return Convert.ToDateTime("1900-01-01").ToString("yyyy-MM-dd"); | 
|                 } | 
|                 else | 
|                 { | 
|                     return Convert.ToDateTime("1900-01-01 00:00:00").ToString("hh:mm:ss"); | 
|                 } | 
|             } | 
|         } | 
|            | 
|           | 
|         //转化为密码 | 
|         public static string StrToPsd(string Str) | 
|         { | 
|             string MmJm = ""; | 
|             int Zf = 0; | 
|             for (int i = 0; i <= Str.Length - 1; i++) | 
|             { | 
|                 Zf = ChrToAsc(Str.Substring(i, 1)) + ChrToAsc(Str.Substring(Str.Length - i - 1, 1)) + Str.Length + 1 + i; | 
|                 MmJm = MmJm + Zf.ToString().Trim(); | 
|             } | 
|             return MmJm; | 
|         } | 
|   | 
|         //字符转ASCII码: | 
|         public static int ChrToAsc(string character) | 
|         { | 
|             if (character.Length == 1) | 
|             { | 
|                 System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); | 
|                 int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0]; | 
|                 return (intAsciiCode); | 
|             } | 
|             else | 
|             { | 
|                 throw new Exception("Character is not valid."); | 
|             } | 
|         } | 
|   | 
|         //ASCII码转字符: | 
|         public static string AscToChr(int asciiCode) | 
|         { | 
|             if (asciiCode >= 0 && asciiCode <= 255) | 
|             { | 
|                 System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); | 
|                 byte[] byteArray = new byte[] { (byte)asciiCode }; | 
|                 string strCharacter = asciiEncoding.GetString(byteArray); | 
|                 return (strCharacter); | 
|             } | 
|             else | 
|             { | 
|                 throw new Exception("ASCII Code is not valid."); | 
|             } | 
|         } | 
|         //数据导出 | 
|         public static bool ExportGrid(Form oFrm) | 
|         { | 
|             foreach (Control ct in oFrm.Controls) | 
|             { | 
|                 switch (ct.GetType().Name) | 
|                 { | 
|                     case "AxVSFlexGrid": | 
|                         try | 
|                         { | 
|                             //string s = ""; | 
|                             //AxVSFlex7.AxVSFlexGrid ogrd; | 
|                             //ogrd = (AxVSFlex7.AxVSFlexGrid)ct; | 
|                             ////选择路径 | 
|                             //SaveFileDialog oDlg = new SaveFileDialog(); | 
|                             //oDlg.Title = "数据导出"; | 
|                             //oDlg.Filter = "数据格式(*.XLS)|*.XLS|数据格式(*.CSV)|*.CSV"; | 
|                             //oDlg.ShowDialog(); | 
|                             //if (oDlg.FileName.Trim() != "") | 
|                             //{ | 
|                             //    ogrd.SaveGrid(oDlg.FileName, VSFlex7.SaveLoadSettings.flexFileTabText, true); | 
|                             //} | 
|                             return true; | 
|                         } | 
|                         catch (Exception e) | 
|                         { | 
|                             return false; | 
|                         } | 
|                     default: | 
|   | 
|                         break; | 
|                 } | 
|             } | 
|             return false; | 
|         } | 
|         //拷贝表格 | 
|         public static bool CopyGrid(Form oFrm) | 
|         { | 
|             foreach (Control ct in oFrm.Controls) | 
|             { | 
|                 switch (ct.GetType().Name) | 
|                 { | 
|                     case "AxVSFlexGrid": | 
|                         try | 
|                         { | 
|                             //string s = ""; | 
|                             //AxVSFlex7.AxVSFlexGrid ogrd; | 
|                             //ogrd = (AxVSFlex7.AxVSFlexGrid)ct; | 
|                             //s = ogrd.get_Cell(VSFlex7.CellPropertySettings.flexcpText, 0, 0, ogrd.Rows - 1, ogrd.Cols - 1).ToString(); | 
|                             //Clipboard.Clear(); | 
|                             //Clipboard.SetText(s); | 
|                             return true; | 
|                         } | 
|                         catch (Exception e) | 
|                         { | 
|                             return false; | 
|                         } | 
|                     default: | 
|   | 
|                         break; | 
|                 } | 
|             } | 
|             return false; | 
|         } | 
|   | 
|         //遍历子控件 | 
|         public static void ForEachControl(Control oControl, bool b) | 
|         { | 
|             foreach (Control ct in oControl.Controls) | 
|             { | 
|                 if (ct.HasChildren == true) | 
|                 { | 
|                     ForEachControl(ct, b); | 
|                 } | 
|                 else | 
|                 { | 
|                     switch (ct.GetType().Name) | 
|                     { | 
|                         case "AxVSFlexGrid": | 
|                             try | 
|                             { | 
|                                 if (b) | 
|                                 { | 
|                                     string s = ""; | 
|                                     //AxVSFlex7.AxVSFlexGrid ogrd; | 
|                                     //ogrd = (AxVSFlex7.AxVSFlexGrid)ct; | 
|                                     //s = ogrd.get_Cell(VSFlex7.CellPropertySettings.flexcpText, 0, 0, ogrd.Rows - 1, ogrd.Cols - 1).ToString(); | 
|                                     //Clipboard.Clear(); | 
|                                     //Clipboard.SetText(s); | 
|                                     //MessageBox.Show("拷贝成功!"); | 
|                                     return; | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     string s = ""; | 
|                                     //AxVSFlex7.AxVSFlexGrid ogrd; | 
|                                     //ogrd = (AxVSFlex7.AxVSFlexGrid)ct; | 
|                                     ////选择路径 | 
|                                     //SaveFileDialog oDlg = new SaveFileDialog(); | 
|                                     //oDlg.Title = "数据导出"; | 
|                                     //oDlg.Filter = "数据格式(*.XLS)|*.XLS|数据格式(*.CSV)|*.CSV"; | 
|                                     //oDlg.ShowDialog(); | 
|                                     //if (oDlg.FileName.Trim() != "") | 
|                                     //{ | 
|                                     //    ogrd.SaveGrid(oDlg.FileName, VSFlex7.SaveLoadSettings.flexFileTabText, true); | 
|                                     //} | 
|                                     //MessageBox.Show("导出成功!"); | 
|                                     return; | 
|                                 } | 
|                             } | 
|                             catch (Exception e) | 
|                             { | 
|                                 return; | 
|                             } | 
|                         default: | 
|   | 
|                             break; | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|          | 
|   | 
|         //得到下查SQL | 
|         public static string GetDownBillSql(ref string HBillType, ref string tRight, ref string FrmName, ref string FrmCaption, ref  string sViewName, string SourceType, long SourceMainID, long SourceSubID) | 
|         { | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             DataSet Ds; | 
|             try | 
|             { | 
|                 //得到下查单据 类型 | 
|                 Ds = oCn.RunProcReturn("exec h_p_Xt_GetDownBillSql " + SourceMainID.ToString() + "," + SourceSubID.ToString() + ",'" + SourceType.Trim() + "'", "gy_czygl"); | 
|                 if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     return ""; | 
|                 } | 
|                 HBillType = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]); | 
|                 tRight = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRightName"]); | 
|                 FrmCaption = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HName"]); | 
|                 FrmName = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HTemplate"]); | 
|                 sViewName = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HViewName"]); | 
|                 return "select top 10000 * from " + sViewName + " Where 源单主内码=" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceInterID"]) + | 
|                     " and 源单子内码=" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceEntryID"]) + | 
|                     " and 源单类型='" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceBillType"]) + "'"; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("关联信息失败,原因: " + e.Message); | 
|                 return ""; | 
|             } | 
|   | 
|   | 
|         } | 
|   | 
|         //得到上查SQL | 
|         public static string GetUpBillSql(ref string HBillType, ref string tRight, ref string FrmName, ref string FrmCaption, ref  string sViewName, string SourceType, long SourceMainID, long SourceSubID) | 
|         { | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             DataSet Ds; | 
|             try | 
|             { | 
|                 //得到下查单据 类型 | 
|                 Ds = oCn.RunProcReturn("exec h_p_Xt_GetUpBillSql " + SourceMainID.ToString() + "," + SourceSubID.ToString() + ",'" + SourceType.Trim() + "'", "gy_czygl"); | 
|                 if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     return ""; | 
|                 } | 
|                 HBillType = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]); | 
|                 tRight = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRightName"]); | 
|                 FrmCaption = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HName"]); | 
|                 FrmName = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HTemplate"]); | 
|                 sViewName = ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HViewName"]); | 
|                 return "select top 10000 * from " + sViewName + " Where hmainid=" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HInterID"]) + | 
|                     " and hsubid=" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HEntryID"]) + | 
|                     " and 单据类型='" + ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]) + "'"; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 MessageBox.Show("关联信息失败,原因: " + e.Message); | 
|                 return ""; | 
|             } | 
|         } | 
|   | 
|         //根据名字获取K3用户ID | 
|         /// <summary> | 
|         /// 根据名字获取K3用户ID | 
|         /// </summary> | 
|         /// <param name="HUserName"></param> | 
|         /// <returns></returns> | 
|         public static long GetUser_K3(string HUserName) | 
|         { | 
|             try | 
|             { | 
|                 ClsSqlHelper oCn = new ClsSqlHelper(); | 
|                 DataSet ds; | 
|                 long HK3UserID = 0; | 
|                 ds = oCn.RunProcReturn("select * from h_v_K3_User where hname='" + HUserName + "'", "xt_xtgnb"); | 
|                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|                 { | 
|                     return 0; | 
|                 } | 
|                 HK3UserID = ClsPub.isLong(ds.Tables[0].Rows[0]["hitemid"]); | 
|                 return HK3UserID; | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 return 0; | 
|             } | 
|         } | 
|   | 
|   | 
|        //得到电脑名和IP | 
|         public static void SetIPAddress() | 
|         { | 
|             IPAddress[] arrIPAddresses = Dns.GetHostAddresses(Dns.GetHostName()); | 
|             foreach (IPAddress ip in arrIPAddresses) | 
|             { | 
|                 if (ip.AddressFamily.Equals(AddressFamily.InterNetwork)) | 
|                 { | 
|                     IPAddress = ip.ToString(); | 
|                     ComputerName = System.Net.Dns.GetHostName(); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         //成本结账得到当前会计年份  | 
|         public static bool Sub_CBGetCurPeriod() | 
|         { | 
|             DataSet Ds = new DataSet(); | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HCBEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return false; | 
|             } | 
|             else | 
|             { | 
|                 ClsPub.CBCurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString()); | 
|                 ClsPub.CBCurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString()); | 
|                 ClsPub.CBCurBDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"].ToString()); | 
|                 ClsPub.CBCurEDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"].ToString()); | 
|                 return true; | 
|             } | 
|         } | 
|         //消费结账得到当前会计年份  | 
|         public static bool Sub_XFGetCurPeriod() | 
|         { | 
|             DataSet Ds = new DataSet(); | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HXFEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return false; | 
|             } | 
|             else | 
|             { | 
|                 ClsPub.XFCurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString()); | 
|                 ClsPub.XFCurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString()); | 
|                 ClsPub.XFCurBDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"].ToString()); | 
|                 ClsPub.XFCurEDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"].ToString()); | 
|                 return true; | 
|             } | 
|         } | 
|         //考勤结账得到当前会计年份  | 
|         public static bool Sub_KQGetCurPeriod() | 
|         { | 
|             DataSet Ds = new DataSet(); | 
|             ClsSqlHelper oCn = new ClsSqlHelper(); | 
|             Ds = oCn.RunProcReturn("select top 1 HYear,HPeriod,HBeginDate,HEndDate from xt_AcCountPeriod where HKqEndFlag=0  order by HYear,HPeriod", "xt_AcCountPeriod"); | 
|             if (Ds == null || Ds.Tables[0].Rows.Count == 0) | 
|             { | 
|                 return false; | 
|             } | 
|             else | 
|             { | 
|                 ClsPub.KQCurYear = ClsPub.isInt(Ds.Tables[0].Rows[0]["HYear"].ToString()); | 
|                 ClsPub.KQCurPeriod = ClsPub.isInt(Ds.Tables[0].Rows[0]["HPeriod"].ToString()); | 
|                 ClsPub.KQCurBDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"].ToString()); | 
|                 ClsPub.KQCurEDate = ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"].ToString()); | 
|                 return true; | 
|             } | 
|         } | 
|   | 
|         //设置 年 月 下拉框 | 
|         public static void Sub_SetYearPeriodCmb(ComboBox oYearCmb,ComboBox oPeriodCmb) | 
|         { | 
|             oYearCmb.Items.Clear();  | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 10); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 9); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 8); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 7); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 6); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 5); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 4); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 3); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 2); | 
|             oYearCmb.Items.Add(DateTime.Today.Year - 1); | 
|             oYearCmb.Items.Add(DateTime.Today.Year); | 
|             oYearCmb.Items.Add(DateTime.Today.Year + 1); | 
|             oYearCmb.Items.Add(DateTime.Today.Year + 2); | 
|             oYearCmb.Items.Add(DateTime.Today.Year + 3); | 
|             oYearCmb.Items.Add(DateTime.Today.Year + 4); | 
|             oYearCmb.SelectedIndex = 10; | 
|             oPeriodCmb.Items.Clear(); | 
|             //oPeriodCmb.Items.Add("0"); | 
|             oPeriodCmb.Items.Add("1"); | 
|             oPeriodCmb.Items.Add("2"); | 
|             oPeriodCmb.Items.Add("3"); | 
|             oPeriodCmb.Items.Add("4"); | 
|             oPeriodCmb.Items.Add("5"); | 
|             oPeriodCmb.Items.Add("6"); | 
|             oPeriodCmb.Items.Add("7"); | 
|             oPeriodCmb.Items.Add("8"); | 
|             oPeriodCmb.Items.Add("9"); | 
|             oPeriodCmb.Items.Add("10"); | 
|             oPeriodCmb.Items.Add("11"); | 
|             oPeriodCmb.Items.Add("12"); | 
|             oPeriodCmb.Text = DateTime.Today.Month.ToString(); | 
|         } | 
|   | 
|         /// <summary>    | 
|         /// DataTable转成Json     | 
|         /// </summary>    | 
|         /// <param name="jsonName"></param>    | 
|         /// <param name="dt"></param>    | 
|         /// <returns></returns>    | 
|         public static string DataTableToJson(DataTable dt, string jsonName) | 
|         { | 
|             StringBuilder Json = new StringBuilder(); | 
|             if (string.IsNullOrEmpty(jsonName)) | 
|                 jsonName = dt.TableName; | 
|             Json.Append("{" + jsonName + ":["); | 
|             //Json.Append("["); | 
|             if (dt.Rows.Count > 0) | 
|             { | 
|                 for (int i = 0; i < dt.Rows.Count; i++) | 
|                 { | 
|                     Json.Append("{"); | 
|                     for (int j = 0; j < dt.Columns.Count; j++) | 
|                     { | 
|                         Type type = dt.Rows[i][j].GetType(); | 
|                         Json.Append("" + dt.Columns[j].ColumnName.ToString().ToLower() + ":" + StringFormat(dt.Rows[i][j].ToString(), type)); | 
|                         if (j < dt.Columns.Count - 1) | 
|                         { | 
|                             Json.Append(","); | 
|                         } | 
|                     } | 
|                     Json.Append("}"); | 
|                     if (i < dt.Rows.Count - 1) | 
|                     { | 
|                         Json.Append(","); | 
|                     } | 
|                 } | 
|             } | 
|             //Json.Append("]}"); | 
|             Json.Append("]}"); | 
|             Json.Replace(Convert.ToChar("\""), Convert.ToChar("\'")); | 
|             return Json.ToString(); | 
|         } | 
|   | 
|   | 
|         /// <summary>    | 
|         /// 格式化字符型、日期型、布尔型    | 
|         /// </summary>    | 
|         /// <param name="str"></param>    | 
|         /// <param name="type"></param>    | 
|         /// <returns></returns>    | 
|         private static string StringFormat(string str, Type type) | 
|         { | 
|             if (type == typeof(string)) | 
|             { | 
|                 str = String2Json(str); | 
|                 str = "\"" + str + "\""; | 
|             } | 
|             else if (type == typeof(DateTime)) | 
|             { | 
|                 str = "\"" + str + "\""; | 
|             } | 
|             else if (type == typeof(bool)) | 
|             { | 
|                 str = str.ToLower(); | 
|             } | 
|             return str; | 
|         } | 
|   | 
|   | 
|   | 
|   | 
|         /// <summary>    | 
|         /// 过滤特殊字符    | 
|         /// </summary>    | 
|         /// <param name="s"></param>    | 
|         /// <returns></returns>    | 
|         private static string String2Json(String s) | 
|         { | 
|             StringBuilder sb = new StringBuilder(); | 
|             for (int i = 0; i < s.Length; i++) | 
|             { | 
|                 char c = s.ToCharArray()[i]; | 
|                 switch (c) | 
|                 { | 
|                     case '\"': | 
|                         sb.Append("\\\""); break; | 
|                     case '\\': | 
|                         sb.Append("\\\\"); break; | 
|                     case '/': | 
|                         sb.Append("\\/"); break; | 
|                     case '\b': | 
|                         sb.Append("\\b"); break; | 
|                     case '\f': | 
|                         sb.Append("\\f"); break; | 
|                     case '\n': | 
|                         sb.Append("\\n"); break; | 
|                     case '\r': | 
|                         sb.Append("\\r"); break; | 
|                     case '\t': | 
|                         sb.Append("\\t"); break; | 
|                     default: | 
|                         sb.Append(c); break; | 
|                 } | 
|             } | 
|             return sb.ToString(); | 
|         } | 
|   | 
|         //拼接sql,按车间,工作中心查询 | 
|         public static string SpliceSQL(string czymc,string ListName) | 
|         { | 
|             DataSet ds; | 
|             ClsSqlHelper oCN = new ClsSqlHelper(); | 
|             string sql = ""; | 
|   | 
|             //判断是否有查询列表所有信息权限 | 
|             if (!Security_Log("Xt_List_All", 1, false, czymc)) | 
|             { | 
|                 //无 | 
|                 switch (ListName) | 
|                 { | 
|                     case "工艺路线列表": | 
|                         sql = " and HCenterID in (select HWorkCenterID from Gy_UserWorkCenterRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|                         break; | 
|                     case "生产订单列表": | 
|                         sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|                         break; | 
|                     case "工序派工单列表": | 
|                         sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|                         break; | 
|                     case "工序派工单明细列表": | 
|                         sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|                         break; | 
|                     case "工序汇报单列表": | 
|                         sql = " and HCenterID in (select HWorkCenterID from Gy_UserWorkCenterRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|                         break; | 
|                     case "生产车间工序报表": | 
|                         sql = ",'" + czymc +"'"; | 
|                         break; | 
|                     case "工序在制品报表": | 
|                         sql = ",'" + czymc + "'"; | 
|                         break; | 
|                     case "工序汇报日报表": | 
|                         sql = ",'" + czymc + "'"; | 
|                         break; | 
|                     case "计件工资报表": | 
|                         sql = ",'" + czymc + "'"; | 
|                         break; | 
|                     case "计件工资汇总报表": | 
|                         sql = ",'" + czymc + "'"; | 
|                         break; | 
|                 } | 
|                 return sql; | 
|             } | 
|             else | 
|             { | 
|                 //有 | 
|                 return sql; | 
|             } | 
|   | 
|             //ds = oCN.RunProcReturn("select * from gy_czygl where Czymc='" + czymc + "'", "gy_czygl"); | 
|             ////判断是否查询到相关用户信息 | 
|             //if (ds != null || ds.Tables[0].Rows.Count != 0) | 
|             //{ | 
|             //    Int64 HManagerFlag = Convert.ToInt64(ds.Tables[0].Rows[0]["ManagerFlag"]); | 
|             //    if (HManagerFlag == 1)//有管理员权限 | 
|             //    { | 
|             //        return sql; | 
|             //    } | 
|             //    else //没有管理员权限 | 
|             //    { | 
|             //        switch (ListName) | 
|             //        { | 
|             //            case "工艺路线列表": | 
|             //                sql = " and HCenterID in (select HWorkCenterID from Gy_UserWorkCenterRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|             //                break; | 
|             //            case "生产订单列表": | 
|             //                sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|             //                break; | 
|             //            case "工序派工单列表": | 
|             //                sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|             //                break; | 
|             //            case "工序派工单明细列表": | 
|             //                sql = " and HDeptID in (select HDeptID from Gy_UserDeptRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|             //                break; | 
|             //            case "工序汇报单列表": | 
|             //                sql = " and HCenterID in (select HWorkCenterID from Gy_UserWorkCenterRelation where HUserID = (select Czybm from gy_czygl where czymc = '" + czymc + "'))"; | 
|             //                break; | 
|             //        }                    | 
|             //        return sql; | 
|             //    } | 
|             //} | 
|             //else | 
|             //{ | 
|             //    sql = "没有查询到相关用户信息"; | 
|             //    return sql; | 
|             //} | 
|         } | 
|   | 
|     } | 
| } |