namespace LSServerService { using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Runtime.InteropServices; using System.Text; internal class LSDBManage { public SqlConnection conn = null; public static string connectionStr = ""; public static Dictionary dbmanageList = new Dictionary(); public int checkFileLockState(int fileId, int parentId, string name) { int num = 0; try { SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@RetParam", SqlDbType.Int), new SqlParameter("@fileId", SqlDbType.Int), new SqlParameter("@parentId", SqlDbType.Int), new SqlParameter("@name", SqlDbType.VarChar, 64) }; parameterArray[0].Direction = ParameterDirection.ReturnValue; parameterArray[1].Value = fileId; parameterArray[2].Value = parentId; parameterArray[3].Value = name; using (SqlCommand command = new SqlCommand("pr_fm_CheckFileLockState", this.conn)) { command.CommandType = CommandType.StoredProcedure; foreach (SqlParameter parameter in parameterArray) { command.Parameters.Add(parameter); } command.ExecuteNonQuery(); num = int.Parse(parameterArray[0].Value.ToString()); } } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.createFile error is : {0} ", new object[] { exception }); } return num; } public int createFile(int parentId, string name, int fileSize, int creator, int productId) { int num = 0; try { SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@RetParam", SqlDbType.Int), new SqlParameter("@parentId", SqlDbType.Int), new SqlParameter("@name", SqlDbType.VarChar, 500), new SqlParameter("@fileSize", SqlDbType.Int), new SqlParameter("@creator", SqlDbType.Int), new SqlParameter("@productId", SqlDbType.Int) }; parameterArray[0].Direction = ParameterDirection.ReturnValue; parameterArray[1].Value = parentId; parameterArray[2].Value = name; parameterArray[3].Value = fileSize; parameterArray[4].Value = creator; parameterArray[5].Value = productId; using (SqlCommand command = new SqlCommand("pr_fm_createFile", this.conn)) { command.CommandType = CommandType.StoredProcedure; foreach (SqlParameter parameter in parameterArray) { command.Parameters.Add(parameter); } command.ExecuteNonQuery(); num = int.Parse(parameterArray[0].Value.ToString()); } } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.createFile error is : {0} ", new object[] { exception }); } return num; } public bool deleteFile(int fileId) { bool flag = false; try { SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@RetParam", SqlDbType.Int), new SqlParameter("@fileId", SqlDbType.Int) }; parameterArray[0].Direction = ParameterDirection.ReturnValue; parameterArray[1].Value = fileId; using (SqlCommand command = new SqlCommand("pr_fm_deleteFile", this.conn)) { command.CommandType = CommandType.StoredProcedure; foreach (SqlParameter parameter in parameterArray) { command.Parameters.Add(parameter); } command.ExecuteNonQuery(); flag = int.Parse(parameterArray[0].Value.ToString()) == 1; } } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.deleteFile fileId={0} error is : {1} ", new object[] { fileId, exception }); } return flag; } public void dispose() { if (this.conn != null) { try { lock (this.conn) { this.conn.Close(); this.conn.Dispose(); this.conn = null; SqlHelper.conn = null; } } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.dispose error is : {0} ", new object[] { exception }); } } } public bool existFile(int parentId, string name) { bool flag = false; try { SqlCommand command = new SqlCommand(string.Format("select * from P_fm_FileTab where parentId={0} and sName='{1}'", parentId, name), this.conn) { CommandType = CommandType.Text }; using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { flag = true; } } command.Dispose(); } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.existFile error is : {0} ", new object[] { exception }); } return flag; } public static void freeAll() { foreach (KeyValuePair pair in dbmanageList) { pair.Value.dispose(); } } public string getAbsoluteFile(int dwFileId) { if (dwFileId <= 0) { return ""; } string str = ""; try { using (SqlDataReader reader = this.querySql(string.Format("select dbo.[fun_fm_getAbsolutePath]({0}) as absolutePath", dwFileId))) { if ((reader != null) && reader.Read()) { str = reader["absolutePath"].ToString(); } } } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.getAbsoluteFile error is : {0} ", new object[] { exception }); } return str; } public SqlDataReader getDownloadFileList(int parentId, string fileIds, string strProductIds) { try { SqlCommand command = new SqlCommand("pr_fm_getDownloadFileInfo", this.conn) { CommandType = CommandType.StoredProcedure }; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@parentId", SqlDbType.Int), new SqlParameter("@fileIds", SqlDbType.VarChar, 1000), new SqlParameter("@productIds", SqlDbType.VarChar, 1000) }; parameterArray[0].Value = parentId; parameterArray[1].Value = fileIds; parameterArray[2].Value = strProductIds; command.Parameters.Add(parameterArray[0]); command.Parameters.Add(parameterArray[1]); command.Parameters.Add(parameterArray[2]); return command.ExecuteReader(); } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.getDownloadFileList error is : {0} ", new object[] { exception }); } return null; } public string getRelativePath(int parentId) { if (parentId <= 0) { return ""; } string str = ""; try { using (SqlDataReader reader = this.querySql(string.Format("select dbo.[fun_fm_getRelativePath]({0}) as relativePath", parentId))) { if ((reader != null) && reader.Read()) { str = reader["relativePath"].ToString(); } } } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.getRelativePath error is : {0} ", new object[] { exception }); } return str; } public bool init() { try { this.conn = new SqlConnection(connectionStr); this.conn.Open(); SqlHelper.conn = this.conn; return true; } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.init error is : {0} ", new object[] { exception }); } return false; } public SqlDataReader querySql(string strSql) { try { SqlCommand command = new SqlCommand(strSql, this.conn) { CommandType = CommandType.Text }; return command.ExecuteReader(); } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.querySql error is : {0} ", new object[] { exception }); } return null; } public void sendPushData(SortedList smartClients) { try { string str = LSIniFile.ReadValue("/Root/ServerSettings", "PushDataProcedure"); if (str != "") { string[] strArray = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length == 2) { string cmdText = strArray[0]; string str3 = strArray[1]; DataSet set = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, cmdText, "getPushdataTab", null); if (set != null) { for (int i = 0; i < set.Tables.Count; i++) { foreach (DataRow row in set.Tables[i].Rows) { uint key = uint.Parse(row[str3].ToString()); if (smartClients.ContainsKey(key)) { if (smartClients[key].SocketState == 2) { smartClients.Remove(key); } else { C2S2C_SmartResponse structObj = new C2S2C_SmartResponse(true); string s = ""; string str5 = ""; for (int j = 0; j < set.Tables[i].Columns.Count; j++) { if (!(set.Tables[i].Columns[j].ColumnName == str3)) { structObj.dwFieldCount++; string str6 = row[j].ToString().Trim(); str5 = str5 + Encoding.Default.GetBytes(str6).Length.ToString() + "|"; s = s + str6; } } if (s != "") { s = str5 + s; byte[] bytes = Encoding.Default.GetBytes(s); structObj.header.dwLen += (uint) bytes.Length; structObj.dwDataLen = (uint) bytes.Length; byte[] destBytes = new byte[structObj.header.dwLen]; PubUtils.CopyStructToBytes(structObj, destBytes, 0); Buffer.BlockCopy(bytes, 0, destBytes, Marshal.SizeOf(structObj), bytes.Length); smartClients[key].Send(destBytes); destBytes = null; bytes = null; } } } } } } } } } catch (Exception exception) { PubUtils.WriteLog("LSDBManage.sendPushData error is : {0} ", new object[] { exception }); } } } }