public void Replace(int start, int len, string value) { /* * Str = Str.Remove(start, len); * Str = Str.Insert(start, value); * if ((start + len) <= Pos) * { * Pos = Pos - (len - value.Length); * }*/ StringOperate op = new StringOperate(); op.start = start; op.removeLen = len; op.value = value; StringOperate tmp; if (!operateDict.TryGetValue(start, out tmp)) { operateDict.Add(start, op); } else { // 处理 beginSample和 endSample 写到一起的导致插入位置是同一个的问题 // function()end tmp.sibling = op; } }
/// <summary> /// 扫描整个网络,检测哪台电脑的3548端口开放,若开放就返回此服务器的IP地址,否侧返回"" /// </summary> internal string GetServerIPByScreen() { this.iActiveThreadCount = 0; this.bHasGetServerIP = false; DirectoryEntry root = new DirectoryEntry("WinNT:"); DirectoryEntries domains = root.Children; domains.SchemaFilter.Add("domain"); foreach (DirectoryEntry domain in domains) { DirectoryEntries computers = domain.Children; computers.SchemaFilter.Add("computer"); foreach (DirectoryEntry computer in computers) { string[] arr = new string[3]; IPHostEntry iphe = null; try { iphe = Dns.GetHostEntry(computer.Name); arr[0] = domain.Name; arr[1] = computer.Name; if (iphe != null) { arr[2] += iphe.AddressList[0].ToString(); if (bHasGetServerIP) { return(PSetUp.fntWeb_ServerIP); //已经得到了服务器的IP地址 } //启动带参数的线程 Thread thd = new Thread(new ParameterizedThreadStart(TCPCanLine)); thd.Start(arr[2]); } } catch (Exception ex) { StringOperate.Alert(ex.Message); } } } int iTimes = 0;//这里没必要等很长时间,如果服务器开启,瞬间就会有反应,再等时间长了也没用 while (this.iActiveThreadCount > 0) { if (bHasGetServerIP) { return(PSetUp.fntWeb_ServerIP); //已经得到了服务器的IP地址 } System.Threading.Thread.Sleep(100); iTimes++; if (iTimes > 60) { break; } } return(""); }
//测试连接 private void TCPCanLine(object objIP) { this.iActiveThreadCount++; IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(objIP.ToString()), PSetUp.fntWeb_ServerPort); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.SendTimeout = 2000; server.ReceiveTimeout = 2000; try { server.Connect(ipep); //试着连接服务器 server.Send(Encoding.Default.GetBytes("Test Connection")); //链接成功了 PSetUp.fntWeb_ServerIP = objIP.ToString(); this.bHasGetServerIP = true; StringOperate.Alert("检测到服务器的IP地址是:" + objIP.ToString()); } catch (Exception e) { } iActiveThreadCount--; if (server.Connected) { server.Shutdown(SocketShutdown.Both); } server.Close(); }
/// <summary> /// 得到一个数据库中的所有表名称 /// </summary> public ArrayList GetAllTableNames() { System.Collections.ArrayList tableNames = new System.Collections.ArrayList(); string strcmd = "2AllTablesぺ" + this.Connstr + "ぺ"; string str = this.tsp.TCPString(strcmd); if (str.StartsWith("Error")) { StringOperate.Alert(str); } else { string[] strArr = str.Split(new char[] { 'ぺ' }); foreach (string s in strArr) { if (s.Length > 0 && !tableNames.Contains(s)) { tableNames.Add(s); } } } return(tableNames); }
public object FirstValue(string SqlString, string[] arrParamName, object[] arrParamValue) { string strcmd = "2FirstValueぺ" + this.Connstr + "ぺ" + SqlString + "ぺ"; if (arrParamName != null) { for (int i = 0; i < arrParamName.Length; i++) { strcmd += (arrParamName[i] + "$" + arrParamValue[i].GetType().ToString() + "$" + arrParamValue[i].ToString() + "ぺ"); } } strcmd = strcmd.TrimEnd(new char[] { 'ぺ' }); string str = this.tsp.TCPString(strcmd); if (str.StartsWith("Error")) { StringOperate.Alert(str); return(""); } else { return(str); } }
public int Excute(string SqlString, string[] arrParamName, object[] arrParamValue) { string strcmd = "2Excuteぺ" + this.Connstr + "ぺ" + SqlString + "ぺ"; if (arrParamName != null) { for (int i = 0; i < arrParamName.Length; i++) { if (arrParamName[i] == null || arrParamValue[i] == null) { continue; } strcmd += (arrParamName[i] + "$" + arrParamValue[i].GetType().ToString() + "$" + arrParamValue[i].ToString() + "ぺ"); } } strcmd = strcmd.TrimEnd(new char[] { 'ぺ' }); string str = this.tsp.TCPString(strcmd); if (str.StartsWith("Error")) { StringOperate.Alert(str); return(0); } else { return(Convert.ToInt16(str)); } }
/// <summary> /// 把一个DataTable写入到数据库中(新建),返回插入行数,并添加新的标识列【ID20】因为ID列有可能和其它表关联,这个ID20是一个无关联的自动编号列,如果原先有ID20这一列,会删去这一列。 /// </summary> public int CreateTable(DataTable dt, string tbName) { byte[] btArr = this.Ser.Serialize((object)dt); string strcmd = "4CreateTableぺ" + this.Connstr + "ぺ" + tbName + "ぺ" + btArr.Length.ToString(); string str = this.tsp.TCPUpTable(strcmd, btArr); if (str.StartsWith("Error")) { StringOperate.Alert(str); return(0); } return(Convert.ToInt16(str)); }
/// <summary> /// 根据查询语句从数据库中读取一个文件,并保存到指定的目录下,返回是否成功 /// </summary> public bool ReadFile(string sql, string createFilePath) { string strcmd = "2ReadFileぺ" + this.Connstr + "ぺ" + sql + "ぺぺ" + createFilePath; string str = this.tsp.TCPString(strcmd); if (str.StartsWith("Error") || str.Length > 0) { StringOperate.Alert(str); return(false); } else { return(true); } }
public DbClient(string myConnectionString) { string IP = "127.0.0.1"; int iPort = 3547; //如果是作为客户端使用 if (PSetUp.bUsingType_Client) { iPort = 3546; IP = PSetUp.fntWeb_ServerIP; myConnectionString = myConnectionString.Replace(AllData.StartUpPath, "[MD3DToolsBasePath]"); } else { #region//检查外部数据提供程序是否已经启动MD3DToolsData.exe,并自动启动 try { if (Sys.Is64BitOPSystem) { System.Diagnostics.Process[] processArr = System.Diagnostics.Process.GetProcessesByName("MD3DToolsData"); if (processArr.Length == 0) { string exepath = AllData.StartUpPath + "\\MD3DToolsData.exe"; if (File.Exists(exepath)) { System.Diagnostics.Process.Start(exepath); System.Threading.Thread.Sleep(400); } else { StringOperate.Alert("检测到没有启动迈迪数据程序“MD3DtoolsData.exe”,这可能导致数据访问不正常!"); } } } } catch (Exception ea) { //string str = ""; } #endregion } this.ConnectionString = myConnectionString; this.tsp = new TransAccess(IP, iPort); this.Ser = new SerializeInfo(); }
/// <summary> /// 把一个文件存入数据库,(文件路径,sql语句,文件参数名@file ,要加密吗 ),返回受影响的行数 /// </summary> public int WriteFile(string FilePath, string SqlString, string ParamName, bool Add)//有Param,如@aaa,这个参数代表文件 { if (!System.IO.File.Exists(FilePath)) { return(0); } string strcmd = "2WriteFileぺ" + this.Connstr + "ぺ" + SqlString + "ぺ" + ParamName + "ぺ" + FilePath + "ぺ" + Add.ToString(); string str = this.tsp.TCPString(strcmd); if (str.StartsWith("Error")) { StringOperate.Alert(str); return(0); } else { return(Convert.ToInt16(str)); } }
public DataTable DBTable(string SqlString, string[] arrParamName, object[] arrParamValue) { string strcmd = "3DBTableぺ" + this.Connstr + "ぺ" + SqlString + "ぺ"; if (arrParamName != null) { for (int i = 0; i < arrParamName.Length; i++) { strcmd += (arrParamName[i] + "$" + arrParamValue[i].GetType().ToString() + "$" + arrParamValue[i].ToString() + "ぺ"); } } strcmd = strcmd.TrimEnd(new char[] { 'ぺ' }); string strError = ""; DataTable dt = this.tsp.TCPDataTable(strcmd, ref strError); if (strError.Length > 0) { StringOperate.Alert(strError); } return(dt); }
public void InsertString(int start, string value) { //Str = Str.Insert(startPos, value); //Pos += value.Length; StringOperate op = new StringOperate(); op.start = start; op.value = value; StringOperate tmp; if (!operateDict.TryGetValue(start, out tmp)) { operateDict.Add(start, op); } else { // 处理 beginSample和 endSample 写到一起的导致插入位置是同一个的问题 // function()end tmp.sibling = op; } }
/// <summary> /// 执行多个SQL语句,,成功返回“”,出错返回ErrorServer: /// </summary> public string Excute(string[] SqlArr) { string strcmd = "2ExcuteArrぺ" + this.Connstr + "ぺ"; foreach (string s in SqlArr) { strcmd += (s + "ぺ"); } strcmd = strcmd.TrimEnd(new char[] { 'ぺ' }); string str = this.tsp.TCPString(strcmd); if (str.StartsWith("Error")) { StringOperate.Alert(str); return(""); } else { return(str); } }
protected void btnSave_Click(object sender, EventArgs e) { if (ishasuser()) { MessageBox("该用户名已经存在,请重新输入!"); return; } if (!StringOperate.IsCheckEngNumUnderLine(txtUserName.Text.Trim())) { MessageBox("用户名需由字母、数字或下划线组成,请重新输入!"); return; } T_WEBMANAGEEntity FM = new T_WEBMANAGEEntity(); FM.ID = Sequence.GetNextValue("SEQ_T_WEBMANAGE"); FM.USERNAME = txtUserName.Text.Trim(); FM.PASSWORD = Names.EncryptPassword(txtPassword.Text.Trim()); FM.TRUENAME = txtTrueName.Text.Trim(); FM.TELEPHONE = txtTelephone.Text.Trim(); FM.DEPT = txtDept.Text.Trim(); FM.CREATETIME = DateTime.Now; FM.STATUS = 0; FM.Save(); foreach (TreeNode n in trNode.Nodes) { if (n.Checked) { T_WEBMANAGEROLEEntity MT = new T_WEBMANAGEROLEEntity(); MT.ID = Sequence.GetNextValue("SEQ_T_WEBMANAGEROLE"); MT.USERNAME = FM.USERNAME; MT.NODEID = int.Parse(n.Value); MT.Save(); GetParentID(FM.USERNAME, MT.NODEID.ToString()); } DiGui(n, FM.USERNAME); } Response.Redirect("adminList.aspx"); }