/// <summary> /// 得到所有GM帐号信息 /// </summary> /// <returns>返回GM帐号信息的消息包</returns> public Message GM_QueryList(int index,int pageSize,int userID) { GMLogAPI logAPI = new GMLogAPI(); ArrayList rowList = new ArrayList(); DataSet ds = null; try { if (userID == 0) { ds = GMUserInfo.SelectAll(); } else { ds = GMUserInfo.SelectAll(userID); } if (ds.Tables[0].Rows.Count <= 0) { return Message.COMMON_MES_RESP(LanguageAPI.API_UserInfoAPI_NoUserList, Msg_Category.USER_ADMIN, ServiceKey.USER_QUERY_RESP,TagName.ERROR_Msg,TagFormat.TLV_STRING); } else { //总页数 int pageCount = 0; pageCount = ds.Tables[0].Rows.Count % pageSize; if (pageCount > 0) { pageCount = ds.Tables[0].Rows.Count / pageSize + 1; } else pageCount = ds.Tables[0].Rows.Count / pageSize; //分页显示 if (index + pageSize > ds.Tables[0].Rows.Count) { pageSize = ds.Tables[0].Rows.Count - index; } logAPI.writeTitle(LanguageAPI.API_UserInfoAPI_AccountInfo,LanguageAPI.API_UserInfoAPI_AccountInfo + LanguageAPI.API_Success + " !"); Query_Structure[] structList = new Query_Structure[pageSize]; logAPI.writeContent(LanguageAPI.Logic_UserValidate_User,LanguageAPI.API_UserInfoAPI_Password,LanguageAPI.API_UserInfoAPI_MAC); for (int i = index; i < index + pageSize; i++) { Query_Structure strut = new Query_Structure(12); strut.AddTagKey(TagName.User_ID, TagFormat.TLV_INTEGER, 4, TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[0])); byte[] bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, ds.Tables[0].Rows[i].ItemArray[1]); strut.AddTagKey(TagName.UserName, TagFormat.TLV_STRING, (uint)bytes.Length, bytes); bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, ds.Tables[0].Rows[i].ItemArray[2]); strut.AddTagKey(TagName.PassWord, TagFormat.TLV_STRING, (uint)bytes.Length, bytes); string mac; if (ds.Tables[0].Rows[i].IsNull(3) == false) mac = ds.Tables[0].Rows[i].ItemArray[3].ToString(); else mac = ""; bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, mac); strut.AddTagKey(TagName.MAC, TagFormat.TLV_STRING, (uint)bytes.Length, bytes); //使用时效 object limit; if (ds.Tables[0].Rows[i].IsNull(8) == false) limit = ds.Tables[0].Rows[i].ItemArray[8]; else limit = ""; bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_DATE, limit); strut.AddTagKey(TagName.Limit, TagFormat.TLV_DATE, (uint)bytes.Length, bytes); //真实姓名 object realName; if (ds.Tables[0].Rows[i].IsNull(4) == false) realName = ds.Tables[0].Rows[i].ItemArray[4]; else realName = ""; bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, realName); strut.AddTagKey(TagName.RealName, TagFormat.TLV_STRING, (uint)bytes.Length, bytes); //部门ID bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[5]); strut.AddTagKey(TagName.DepartID, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes); //部门名称 bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING, ds.Tables[0].Rows[i].ItemArray[6]); strut.AddTagKey(TagName.DepartName, TagFormat.TLV_STRING, (uint)bytes.Length, bytes); //状态 bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[7]); strut.AddTagKey(TagName.User_Status, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes); //总页数 strut.AddTagKey(TagName.PageCount, TagFormat.TLV_INTEGER, 4, TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, pageCount)); //在线状态 bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[9]); strut.AddTagKey(TagName.OnlineActive, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes); bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[10]); strut.AddTagKey(TagName.SysAdmin, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes); structList[i - index] = strut; logAPI.writeData(ds.Tables[0].Rows[i].ItemArray[1].ToString().Trim(), ds.Tables[0].Rows[i].ItemArray[2].ToString().Trim(), ds.Tables[0].Rows[i].ItemArray[3].ToString().Trim()); } Console.WriteLine(logAPI.Buffer.ToString()); return Message.COMMON_MES_RESP(structList, Msg_Category.USER_ADMIN, ServiceKey.USER_QUERY_RESP, 12); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); return Message.COMMON_MES_RESP(LanguageAPI.API_UserInfoAPI_NoUserList, Msg_Category.USER_ADMIN, ServiceKey.USER_QUERY_RESP,TagName.ERROR_Msg,TagFormat.TLV_STRING); } }
/// <summary> /// 封装用户列表的消息包 /// </summary> /// <returns>完整的消息包</returns> public static byte[] PackUserListMsg(int userID) { string[] userName ; string[] passWd; string[] MAC; int iCurrPos = 0; int iDetailLen = 0; byte[] bDetail = new byte[128]; //调用UserInfo类的函数,把用户表数据读出来存入DATASET里面 DataSet ds = GMUserInfo.SelectAll(userID); userName = new string[ds.Tables[0].Rows.Count]; passWd = new string[ds.Tables[0].Rows.Count]; MAC = new string[ds.Tables[0].Rows.Count]; //遍历用户表所有数据,把用户名、密码、MAC存入Byte数组里面 //iCurrPos记录Byte数组的位置 for(int i=0;i<ds.Tables[0].Rows.Count;i++) { userName[i] = ds.Tables[0].Rows[i][1].ToString(); passWd[i] = ds.Tables[0].Rows[i][2].ToString(); MAC[i] = ds.Tables[0].Rows[i][3].ToString(); byte[] bTmpUserName = System.Text.Encoding.Default.GetBytes(userName[i]); Array.Copy(bTmpUserName,0,bDetail,iCurrPos,bTmpUserName.Length); iCurrPos+=bTmpUserName.Length; byte[] bTmpPassWord = System.Text.Encoding.Default.GetBytes(passWd[i]); Array.Copy(bTmpPassWord,0,bDetail,iCurrPos,bTmpPassWord.Length); iCurrPos+=bTmpPassWord.Length; byte[] bTmpMac = System.Text.Encoding.Default.GetBytes(MAC[i]); Array.Copy(bTmpMac,0,bDetail,iCurrPos,bTmpMac.Length); iCurrPos+=bTmpMac.Length; } //得到消息包的长度 iDetailLen = iCurrPos; //截取多余Byte空间 byte[] detailMsg = Packet_Body.getPacketBody(bDetail); byte[] bHead = new byte[16+ds.Tables[0].Rows.Count*3+iDetailLen]; iCurrPos = 0; //创建序列号ID bHead[iCurrPos++]=System.Convert.ToByte(iSequenceID&255); bHead[iCurrPos++]=System.Convert.ToByte((iSequenceID&65280)>>8); bHead[iCurrPos++]=System.Convert.ToByte((iSequenceID&16711680)>>16); bHead[iCurrPos++]=System.Convert.ToByte((iSequenceID&4278190080)>>32); //消息类型 bHead[iCurrPos++]=0x82; //保留地址 bHead[iCurrPos++]=0x80; //服务健是REQUEST还是RESP bHead[iCurrPos++]=0x01; bHead[iCurrPos++]=0x00; //定义消息体数据的长度,把它存在消息头里面,如果数据是多行的话就循环存储长度 for(int i=0;i<ds.Tables[0].Rows.Count;i++) { bHead[iCurrPos++]=Convert.ToByte(userName[i].Length); bHead[iCurrPos++]=Convert.ToByte(passWd[i].Length); bHead[iCurrPos++]=Convert.ToByte(MAC[i].Length); } //消息创建日期 System.DateTime dt = System.DateTime.Now; bHead[iCurrPos++]=System.Convert.ToByte(dt.Year-1900); bHead[iCurrPos++]=System.Convert.ToByte(dt.Month); bHead[iCurrPos++]=System.Convert.ToByte(dt.Day); bHead[iCurrPos++]=System.Convert.ToByte(dt.Hour); bHead[iCurrPos++]=System.Convert.ToByte(dt.Minute); bHead[iCurrPos++]=System.Convert.ToByte(dt.Second); iSequenceID++; bHead[iCurrPos++]=System.Convert.ToByte(detailMsg.Length&255); bHead[iCurrPos++]=System.Convert.ToByte((detailMsg.Length&65280)>>8); //把消息头和消息体组成一个消息包 Array.Copy(bDetail,0,bHead,iCurrPos,detailMsg.Length); return bHead; }
/// <summary> /// 得到所有GM帐号信息 /// </summary> /// <returns>返回GM帐号信息的消息包</returns> public Message GM_QueryAll(int userID) { GMLogAPI logAPI = new GMLogAPI(); ArrayList rowList = new ArrayList(); DataSet ds = null; try { ds = GMUserInfo.SelectAll(userID); if(ds.Tables[0].Rows.Count<=0) { return Message.COMMON_MES_RESP("FAILURE",Msg_Category.USER_ADMIN,ServiceKey.USER_QUERY_ALL); } else { logAPI.writeTitle(LanguageAPI.API_Display + LanguageAPI.API_UserInfoAPI_AccountInfo,LanguageAPI.API_Display + LanguageAPI.API_UserInfoAPI_AccountInfo + LanguageAPI.API_Success + " !"); Query_Structure[] structList = new Query_Structure[ds.Tables[0].Rows.Count]; logAPI.writeContent(LanguageAPI.Logic_UserValidate_User,LanguageAPI.API_UserInfoAPI_Password,LanguageAPI.API_UserInfoAPI_MAC); for(int i=0;i<ds.Tables[0].Rows.Count;i++) { Query_Structure strut = new Query_Structure((uint)ds.Tables[0].Rows[i].ItemArray.Length); strut.AddTagKey(TagName.User_ID,TagFormat.TLV_INTEGER,4,TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER,ds.Tables[0].Rows[i].ItemArray[0])); byte[] bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING,ds.Tables[0].Rows[i].ItemArray[1]); strut.AddTagKey(TagName.UserName,TagFormat.TLV_STRING,(uint)bytes.Length,bytes); bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING,ds.Tables[0].Rows[i].ItemArray[2]); strut.AddTagKey(TagName.PassWord,TagFormat.TLV_STRING,(uint)bytes.Length,bytes); string mac; if(ds.Tables[0].Rows[i].IsNull(3)==false) mac = ds.Tables[0].Rows[i].ItemArray[3].ToString(); else mac = ""; bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING,mac); strut.AddTagKey(TagName.MAC,TagFormat.TLV_STRING,(uint)bytes.Length,bytes); //使用时效 object limit; if(ds.Tables[0].Rows[i].IsNull(8)==false) limit = ds.Tables[0].Rows[i].ItemArray[8]; else limit = ""; bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_DATE,limit); strut.AddTagKey(TagName.Limit,TagFormat.TLV_DATE,(uint)bytes.Length,bytes); //状态 bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER,ds.Tables[0].Rows[i].ItemArray[7]); strut.AddTagKey(TagName.User_Status,TagFormat.TLV_INTEGER,(uint)bytes.Length,bytes); string realName; if(ds.Tables[0].Rows[i].IsNull(4)==false) realName = ds.Tables[0].Rows[i].ItemArray[4].ToString(); else realName = ""; bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_STRING,realName); strut.AddTagKey(TagName.RealName,TagFormat.TLV_STRING,(uint)bytes.Length,bytes); bytes = TLV_Structure.ValueToByteArray(TagFormat.TLV_INTEGER, ds.Tables[0].Rows[i].ItemArray[10]); strut.AddTagKey(TagName.SysAdmin, TagFormat.TLV_INTEGER, (uint)bytes.Length, bytes); structList[i]=strut; logAPI.writeData(ds.Tables[0].Rows[i].ItemArray[1].ToString().Trim(),ds.Tables[0].Rows[i].ItemArray[2].ToString().Trim(),ds.Tables[0].Rows[i].ItemArray[3].ToString().Trim()); } Console.WriteLine(logAPI.Buffer.ToString()); return Message.COMMON_MES_RESP(structList,Msg_Category.USER_ADMIN,ServiceKey.USER_QUERY_ALL,7); } } catch(SqlException ex) { Console.WriteLine(ex.Message); return Message.COMMON_MES_RESP(LanguageAPI.API_UserInfoAPI_NoUserList,Msg_Category.USER_ADMIN,ServiceKey.USER_QUERY_ALL,TagName.ERROR_Msg,TagFormat.TLV_STRING); } catch(System.Exception ex1) { Console.WriteLine(ex1.Message); return Message.COMMON_MES_RESP(LanguageAPI.API_UserInfoAPI_NoUserList,Msg_Category.USER_ADMIN,ServiceKey.USER_QUERY_ALL,TagName.ERROR_Msg,TagFormat.TLV_STRING); } }