/// <summary> /// 查询按钮、重置按钮点击事件 /// </summary> /// <param name="sender">发送者</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击事件</param> /// <param name="delta">滚轮滚动值</param> private void ClickButton(object sender, POINT mp, MouseButtonsA button, int clicks, int delta) { if (button == MouseButtonsA.Left && clicks == 1) { ControlA control = sender as ControlA; String name = control.Name; if (name == "btnSelectCodeDir") { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (DialogResult.OK == fbd.ShowDialog()) { GetTextBox("txtCodeDir").Text = fbd.SelectedPath; String codeDirCacheDir = DataCenter.GetAppPath() + "\\CODEDIR.txt"; CFileA.Write(codeDirCacheDir, fbd.SelectedPath); Native.Invalidate(); } fbd.Dispose(); } else if (name == "btnSelectDataDir") { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (DialogResult.OK == fbd.ShowDialog()) { GetTextBox("txtDataDir").Text = fbd.SelectedPath; String dataDirCacheDir = DataCenter.GetAppPath() + "\\DATADIR.txt"; CFileA.Write(dataDirCacheDir, fbd.SelectedPath); Native.Invalidate(); } fbd.Dispose(); } else if (name == "btnGenerate") { //GAIA_FUTURE_CPP_S1:PengChen,100%; String codeDir = GetTextBox("txtCodeDir").Text; String dataDir = GetTextBox("txtDataDir").Text; ProjectJidian pJidian = new ProjectJidian(); DataCenter.JidianService.Dir = codeDir; DataCenter.JidianService.GetJidian(ref pJidian); if (pJidian.Lines > 0) { CFileA.Write(dataDir + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".jidian", pJidian.ToString()); GetTextBox("txtResults").Text = pJidian.ToString(); Native.Invalidate(); } } } }
/// <summary> /// 经济指标图表数据源 /// </summary> /// <returns>经济指标图表数据源</returns> public static DataTable QueryMAC_JJZBTB_TJ() { try { // return SpecialCommon.DataHelper.QueryData("MAC_JJZBTB", null, null, null, null, true, "MAC_JJZBTB_TJ").Tables[0]; //定义文件夹 String fileName = DataCenter.GetAppPath() + "\\NecessaryData\\MAC_JJZBTB_TJ"; if (File.Exists(fileName)) { return(JSONHelper.DeserializeObject <DataSet>(File.ReadAllText(fileName)).Tables[0]); } return(null); } catch { return(null); } }
/// <summary> /// 获取分时数据 /// </summary> public static void GetMinuteDatas() { if (m_minuteDatas.Count > 0) { return; } String appPath = DataCenter.GetAppPath(); foreach (String code in m_codedMap.Keys) { String fileName = m_newFileDir + CStrA.ConvertDBCodeToFileName(code); if (!CFileA.IsFileExist(fileName)) { fileName = m_newFileDir + CStrA.ConvertDBCodeToSinaCode(code).ToUpper() + ".txt"; } if (CFileA.IsFileExist(fileName)) { String text = ""; CFileA.Read(fileName, ref text); List <SecurityData> datas = new List <SecurityData>(); StockService.GetHistoryDatasByMinuteStr(text, datas); if (datas.Count > 0) { int rindex = 0; int dataSize = datas.Count; while (rindex < dataSize) { SecurityData d = datas[rindex]; if (rindex == 0) { d.m_avgPrice = d.m_close; } else { SecurityData ld = datas[rindex - 1]; d.m_avgPrice = (ld.m_avgPrice * rindex + d.m_close) / (rindex + 1); } rindex++; } m_minuteDatas[code] = datas; } } } }
/// <summary> /// 获取或设置是否需要创建表 /// </summary> public void CreateTable() { String dataBasePath = DataCenter.GetUserPath() + "\\" + DATABASENAME; if (!CFileA.IsFileExist(dataBasePath)) { //创建数据库文件 SQLiteConnection.CreateFile(dataBasePath); } //创建表 SQLiteConnection conn = new SQLiteConnection(m_connectStr); conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = CREATETABLESQL; cmd.ExecuteNonQuery(); conn.Close(); }
public static Dictionary <long, ParameterType> GetParamType() { if (paramType != null) { return(paramType); } Dictionary <long, ParameterType> dictionary = new Dictionary <long, ParameterType>(); String path = DataCenter.GetAppPath() + @"\\config\\ParameterType.xml"; List <ParameterType> list = (List <ParameterType>)XmlConvertor.Deserialize(typeof(List <ParameterType>), path); list.Sort(new ParameterTypeCompare()); foreach (ParameterType type in list) { if (type.TYPECODE != 0L) { dictionary[type.TYPECODE] = type; } } return(dictionary); }
/// <summary> /// 加载 /// </summary> /// <param name="name">名称</param> public void LoadXml(String name) { if (name == "EmailWindow") { m_xml = new EmailWindow(); } else if (name == "EmailWindow2") { m_xml = new EmailWindow2(); } m_xml.CreateNative(); m_native = m_xml.Native; m_native.Paint = new GdiPlusPaintEx(); m_host = new WinHostEx(); m_host.Native = m_native; m_native.Host = m_host; m_host.HWnd = Handle; m_native.AllowScaleSize = true; m_native.DisplaySize = new SIZE(ClientSize.Width, ClientSize.Height); m_xml.ResetScaleSize(GetClientSize()); m_xml.Native.ResourcePath = DataCenter.GetAppPath() + "\\image"; m_xml.Script = new GaiaScript(m_xml); m_xml.Load(DataCenter.GetAppPath() + "\\config\\" + name + ".html"); m_host.ToolTip = new ToolTipA(); m_host.ToolTip.Font = new FONT("SimSun", 20, true, false, false); (m_host.ToolTip as ToolTipA).InitialDelay = 250; m_native.Update(); Invalidate(); LoginForm loginForm = new LoginForm(); loginForm.ShowDialog(); if (name == "EmailWindow") { (m_xml as EmailWindow).EmailInfo = loginForm.EmailInfo; } else if (name == "EmailWindow2") { (m_xml as EmailWindow2).EmailInfo = loginForm.EmailInfo; } m_xml.LoadData(); }
/// <summary> /// 创建窗体 /// </summary> /// <param name="native">方法库</param> public JidianWindow(INativeBase native) { Load(native, "JidianWindow", "jidianWindow"); RegisterEvents(m_window); String codeDirCachePath = DataCenter.GetAppPath() + "\\CODEDIR.txt"; if (CFileA.IsFileExist(codeDirCachePath)) { String content = ""; CFileA.Read(codeDirCachePath, ref content); GetTextBox("txtCodeDir").Text = content; } String dataDirCacheDir = DataCenter.GetAppPath() + "\\DATADIR.txt"; if (CFileA.IsFileExist(dataDirCacheDir)) { String content = ""; CFileA.Read(dataDirCacheDir, ref content); GetTextBox("txtDataDir").Text = content; } }
static void Main() { FormulaProxy.FormulaInit(); IList <Formula> formulas = FormulaProxy.GetSystemFormulas(); int id = 0; foreach (Formula la in formulas) { Formula formula = new Formula(); FormulaProxy.GetDbFormula(id, ref formula); String text = Marshal.PtrToStringAnsi(formula.src); id++; } DataCenter.StartService(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm mainFrom = new MainForm(); mainFrom.LoadXml("MainFrame"); Application.Run(mainFrom); }
/// <summary> /// 获取基金公司和基金Code的Mapping /// </summary> /// <returns></returns> public static IDictionary <String, String> GetEmCodeCompanyMapping() { IDictionary <String, String> EmCodeCompanyMapping = new Dictionary <String, String>(); // 对应关系文件 String filePath = Path.Combine(DataCenter.GetAppPath(), @"NecessaryData/FundCompcode"); char[] separater1 = "$".ToCharArray(); // "$" char[] separater2 = "}".ToCharArray(); // "}" if (File.Exists(filePath)) { String content = File.ReadAllText(filePath); String[] strRecords = content.Split(separater2, StringSplitOptions.RemoveEmptyEntries); if (strRecords == null || strRecords.Length == 0) { return(EmCodeCompanyMapping); } String[] strColumns = null; foreach (String record in strRecords) { strColumns = record.Split(separater1, StringSplitOptions.RemoveEmptyEntries); if (strColumns == null || strColumns.Length < 2) { continue; } if (!EmCodeCompanyMapping.ContainsKey(strColumns[0])) { EmCodeCompanyMapping.Add(strColumns[0], strColumns[1]); } } } return(EmCodeCompanyMapping); }
//查询专题 /// <summary> /// 经济指标图表数据源 /// </summary> /// <returns>经济指标图表数据源</returns> public static DataTable QueryMAC_JJZBTB() { //while (!AppBaseServices.NecessaryDataIsLoaded) //{ // Thread.Sleep(10); //} //return SpecialCommon.DataHelper.QueryData("MAC_JJZBTB", null, null, null, null).Tables[0]; try { //定义文件夹 String fileName = DataCenter.GetAppPath() + "\\NecessaryData\\MAC_JJZBTB"; if (File.Exists(fileName)) { return(JSONHelper.DeserializeObject <DataSet>(File.ReadAllText(fileName)).Tables[0]); } return(null); } catch { return(null); } }
/// <summary> /// 加载历史数据 /// </summary> /// <param name="history"></param> public static void LoadHistoryDatas() { if (m_historyDatas.Count > 0) { return; } foreach (String code in m_codedMap.Keys) { String fileName = DataCenter.GetAppPath() + "\\day\\" + CStrA.ConvertDBCodeToSinaCode(code).ToUpper() + ".txt"; if (File.Exists(fileName)) { StreamReader sra = new StreamReader(fileName, Encoding.Default); String text = sra.ReadToEnd(); List <SecurityData> datas = new List <SecurityData>(); StockService.GetHistoryDatasByTdxStr(text, datas); if (datas.Count > 0) { m_historyDatas[code] = datas; } } } }
/// <summary> /// 创建股票列表窗体 /// </summary> /// <param name="native">方法库</param> public SecurityList(INativeBase native) { m_native = native; String xmlPath = DataCenter.GetAppPath() + "\\config\\SecurityList.xml"; Native = m_native; LoadFile(xmlPath, null); m_window = FindControl("windowSecurity") as WindowEx; m_invokeEvent = new ControlInvokeEvent(Invoke); m_window.RegisterEvent(m_invokeEvent, EVENTID.INVOKE); //注册点击事件 RegisterEvents(m_window); m_gridSecurities = GetGrid("gridSecurities"); m_gridSelectSecurities = GetGrid("gridSelectSecurities"); m_tvBlock = GetTree("tvBlock"); m_gridSelectedRowsChangedEvent = new ControlEvent(GridSelectedRowsChanged); m_tvBlock.RegisterEvent(m_gridSelectedRowsChangedEvent, EVENTID.GRIDSELECTEDROWSCHANGED); //注册服务 m_securityService = DataCenter.SecurityService; m_securityDataCallBack = new ListenerMessageCallBack(SecurityDataCallBack); m_securityService.RegisterListener(m_securitiesRequestID, m_securityDataCallBack); m_userSecurityService = DataCenter.UserSecurityService; }
/// <summary> /// 加载 /// </summary> /// <param name="name">名称</param> public void LoadXml(String name) { if (name == "MainFrame") { m_xml = new MainFrame(); } m_xml.CreateNative(); m_native = m_xml.Native; m_native.Paint = new GdiPlusPaintEx(); m_host = new WinHostEx(); m_host.Native = m_native; m_native.Host = m_host; m_host.HWnd = Handle; m_native.AllowScaleSize = true; m_native.DisplaySize = new SIZE(ClientSize.Width, ClientSize.Height); m_xml.ResetScaleSize(GetClientSize()); m_xml.Native.ResourcePath = DataCenter.GetAppPath() + "\\config"; m_xml.Load(DataCenter.GetAppPath() + "\\config\\" + name + ".html"); m_host.ToolTip = new ToolTipA(); m_host.ToolTip.Font = new FONT("SimSun", 20, true, false, false); (m_host.ToolTip as ToolTipA).InitialDelay = 250; m_native.Update(); Invalidate(); }
/// <summary> /// 根据时间下载新浪xls数据文件 /// </summary> public static void DownLoadSinaXlsDataByDate(String dateStr) { String contentPath = DataCenter.GetAppPath() + "\\download\\xls\\"; String urlTemplate = "http://market.finance.sina.com.cn/downxls.php?date={0}&symbol={1}"; foreach (String code in m_codedMap.Keys) { String filePath = contentPath + code + "-" + dateStr + ".xls"; String url = String.Format(urlTemplate, dateStr, code.ToLower()); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream responseStream = response.GetResponseStream(); byte[] bArr = new byte[1024]; int size = responseStream.Read(bArr, 0, (int)bArr.Length); Stream fs = new FileStream(filePath, FileMode.Create); while (size > 0) { fs.Write(bArr, 0, size); size = responseStream.Read(bArr, 0, (int)bArr.Length); } fs.Close(); responseStream.Close(); } }
/// <summary> /// 触发秒表事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="timerID">秒表ID</param> private void CallTimerEvent(object sender, int timerID) { if (m_isOver) { return; } if (m_sky != null) { if (m_currentQuestion != null && m_mode >= 5 && m_currentQuestion.m_type != "极限") { TimeSpan ts = DateTime.Now - m_bulletTime; int bollSeconds = 30, totalSeconds = (int)ts.TotalSeconds; m_sky.Text = ""; if (totalSeconds >= bollSeconds) { Sound.Play("sound\\attbomb.wav"); m_sky.CreateBullets(6); m_bulletTime = DateTime.Now; } else if (totalSeconds == bollSeconds - 1) { Sound.Play("sound\\1.wav"); m_sky.Text = "1"; } else if (totalSeconds == bollSeconds - 2) { Sound.Play("sound\\2.wav"); m_sky.Text = "2"; } else if (totalSeconds == bollSeconds - 3) { Sound.Play("sound\\3.wav"); m_sky.Text = "3"; } else if (totalSeconds == bollSeconds - 4) { Sound.Play("sound\\bomb.wav"); m_sky.Text = "准备炸弹"; } TimeSpan ts2 = DateTime.Now - m_shadowTime; int shadownTime = 1, totalSeconds2 = (int)ts2.TotalSeconds; if (totalSeconds2 >= shadownTime) { m_shadowTime = DateTime.Now; } m_sky.OnTimer(timerID); } if (m_currentQuestion != null && (m_currentQuestion.m_type == "记忆" || m_currentQuestion.m_type == "算数")) { if (m_currentQuestion.m_answer == m_txtAnswer.Text) { for (int i = 0; i < 5; i++) { AddBarrage("回答正确", 0, 4 + i); } ChangeQuestion(); } } } double m_oldCurrentTick = m_currentTick; if (m_currentTick > 0) { TimeSpan ts = DateTime.Now - m_lastTime; bool bulletIsClick = true; foreach (Bullet bullet in m_sky.m_bullets) { if (!bullet.IsClick) { bulletIsClick = false; } } if (bulletIsClick) { m_currentTick -= (double)ts.Milliseconds / 1000; } if (m_currentTick <= 0) { if (m_questions != null) { m_answers[m_currentQuestion.m_title] = m_txtAnswer.Text; } if (m_currentQuestion != null && m_currentQuestion.m_type == "极限") { Native.ExportToImage(DataCenter.GetAppPath() + "\\成绩截图.jpg"); } m_lblTime.Text = "时间到了"; m_txtAnswer.Text = m_currentQuestion.m_type; m_currentTick = 0; ChangeQuestion(); } else { if (m_currentQuestion.m_type == "记忆") { if (m_totalTick - m_currentTick > m_totalTick / 2) { m_txtQuestion.Text = "不可见"; m_txtAnswer.ReadOnly = false; if (m_txtAnswer.Text == "请迅速记忆上面这串数字,在此文字消失时打出刚才那串数字") { m_txtAnswer.Text = ""; } } if (m_currentTick <= 2) { m_txtQuestion.Text = m_currentQuestion.m_answer; } } double finishTime = (double)((TimeSpan)(DateTime.Now - m_firstTime)).TotalMilliseconds / 1000; m_lblTime.Text = "还剩" + m_currentTick.ToString("0.00") + "秒 已用时" + finishTime.ToString("0.00") + "秒"; if (finishTime > 60 * m_examMinute) { m_answers[m_currentQuestion.m_title] = m_txtAnswer.Text; String file = DataCenter.GetAppPath() + "\\Result.txt"; StringBuilder sb = new StringBuilder(); int index = 1; foreach (String question in m_answers.Keys) { sb.AppendLine(index.ToString() + "." + question); sb.AppendLine(m_answers[question]); index++; } CFileA.Write(file, sb.ToString()); String examName = ""; CFileA.Read(DataCenter.GetAppPath() + "\\WriteYourName.txt", ref examName); String url = "http://" + m_ip + ":10009/sendresult?name=" + examName; HttpPostService postService = new HttpPostService(); postService.Post(url, sb.ToString()); m_txtAnswer.Text = "考试时间到,请等待考试结果!"; Native.Invalidate(); m_isOver = true; } } } if (m_mode == 5) { if (m_currentQuestion.m_type == "打字" || m_currentQuestion.m_type == "极限") { if (m_tick % 5 == 0) { AddBarrage(m_rd.Next(0, 2) == 0 ? "111" : "222", 2, m_rd.Next(3, 20)); } } } m_lastTime = DateTime.Now; m_tick++; if (m_tick > 10000) { m_tick = 0; } Native.Invalidate(); }
/// <summary> /// 下载所有的A股市场股票历史数据 /// </summary> public static void DownAllStockHistory(int index) { List <KwItem> availableItems = new List <KwItem>(); foreach (KwItem item in EMSecurityService.KwItems.Values) { availableItems.Add(item); } int itemsSize = availableItems.Count; int complexRightIndex = 0; String saveFilePath = ""; for (int i = index * 50; i < itemsSize && i < (index + 1) * 50; i++) { KwItem item = availableItems[i]; complexRightIndex = 0; for (; complexRightIndex < m_complexRightType.Count; complexRightIndex++) { try { String cmd = String.Format(GetSearchCmd(m_complexRightType[complexRightIndex], m_lstAIndicators, item.Code), Environment.NewLine); if (String.IsNullOrEmpty(cmd)) { continue; } DataSet dsResult = DataCenter.DataQuery.QueryIndicate(cmd) as DataSet; if (dsResult == null || dsResult.Tables.Count == 0) { continue; } IDictionary <String, String[]> dicResult = GetDictionaryFromDataSet(dsResult, m_lstAIndicators); if (dicResult.Count > 0) { String code = item.Code; if (code.IndexOf(".") != -1) { code = code.Substring(code.IndexOf(".") + 1) + code.Substring(0, code.IndexOf(".")); } String dir = DataCenter.GetAppPath() + "\\day\\"; if (!CFileA.IsDirectoryExist(dir)) { CFileA.CreateDirectory(dir); } saveFilePath = dir + code + ".txt"; StringBuilder sbResult = new StringBuilder(); sbResult.AppendLine(item.Code + " " + item.Name + " 日线 前复权"); sbResult.AppendLine(" 日期 开盘 最高 最低 收盘 成交量 成交额"); foreach (KeyValuePair <String, String[]> pair in dicResult) { sbResult.AppendLine(FormatStockInfo(pair.Value, ",")); } sbResult.AppendLine("OWCHART荣誉出品"); CFileA.Write(saveFilePath, sbResult.ToString()); sbResult = null; } } catch (Exception ex) { Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace); } } } }
/// <summary> /// 开始工作 /// </summary> private static void StartWork() { Dictionary <String, String> m_codesMap = new Dictionary <String, String>(); String codes = ""; while (true) { if (m_securities.Count == 0) { String codesStr = ""; CFileA.Read(DataCenter.GetAppPath() + "\\codes.txt", ref codesStr); String[] strs = codesStr.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); StringBuilder sb = new StringBuilder(); for (int i = 0; i < strs.Length; i++) { String[] subStrs = strs[i].Split(','); Security security = new Security(); security.m_code = subStrs[0]; security.m_name = subStrs[1]; lock (m_securities) { m_securities.Add(security); } m_codesMap[security.m_code] = security.m_name; codes += security.m_code; codes += ","; if (!security.m_code.StartsWith("A")) { sb.Append(security.m_code + "," + security.m_name + "\r\n"); } } CFileA.Write(DataCenter.GetAppPath() + "\\codes.txt", sb.ToString()); } if (codes != null && codes.Length > 0) { if (codes.EndsWith(",")) { codes.Remove(codes.Length - 1); } String[] strCodes = codes.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); int codesSize = strCodes.Length; String latestCodes = ""; for (int i = 0; i < codesSize; i++) { latestCodes += strCodes[i]; if (i == codesSize - 1 || (i > 0 && i % 50 == 0)) { String latestDatasResult = GetSinaLatestDatasStrByCodes(latestCodes); if (latestDatasResult != null && latestDatasResult.Length > 0) { List <SecurityLatestData> latestDatas = new List <SecurityLatestData>(); GetLatestDatasBySinaStr(latestDatasResult, 0, latestDatas); int latestDatasSize = latestDatas.Count; for (int j = 0; j < latestDatasSize; j++) { SecurityLatestData latestData = latestDatas[j]; if (latestData.m_close == 0) { latestData.m_close = latestData.m_buyPrice1; } if (latestData.m_close == 0) { latestData.m_close = latestData.m_sellPrice1; } lock (m_latestDatas) { m_latestDatas[latestData.m_securityCode] = latestData; } } latestDatas.Clear(); } latestCodes = ""; } else { latestCodes += ","; } } } Thread.Sleep(1); } }
/// <summary> /// 接收消息 /// </summary> /// <param name="message">消息</param> public override void OnReceive(CMessage message) { base.OnReceive(message); if (DataCenter.IsFull && message.m_functionID == FUNCTIONID_SENDALL) { DataCenter.ServerChatService.SendAll(message); } if (message.m_functionID == FUNCTIONID_GETHOSTS) { List <ChatHostInfo> datas = new List <ChatHostInfo>(); int type = 0; ChatService.GetHostInfos(datas, ref type, message.m_body, message.m_bodyLength); if (type != 2) { int datasSize = datas.Count; for (int i = 0; i < datasSize; i++) { ChatHostInfo hostInfo = datas[i]; //全节点 if (hostInfo.m_type == 1) { if (hostInfo.m_ip != "127.0.0.1") { OwLibSV.ChatHostInfo serverHostInfo = new OwLibSV.ChatHostInfo(); serverHostInfo.m_ip = hostInfo.m_ip; serverHostInfo.m_serverPort = hostInfo.m_serverPort; serverHostInfo.m_type = hostInfo.m_type; DataCenter.ServerChatService.AddServerHosts(serverHostInfo); String newServer = hostInfo.m_ip + ":" + CStr.ConvertIntToStr(hostInfo.m_serverPort); List <ChatHostInfo> hostInfos = new List <ChatHostInfo>(); UserCookie cookie = new UserCookie(); if (DataCenter.UserCookieService.GetCookie("DANDANSERVERS", ref cookie) > 0) { hostInfos = JsonConvert.DeserializeObject <List <ChatHostInfo> >(cookie.m_value); } int hostInfosSize = hostInfos.Count; bool contains = false; for (int j = 0; j < hostInfosSize; j++) { ChatHostInfo oldHostInfo = hostInfos[j]; String key = oldHostInfo.ToString(); if (key == newServer) { contains = true; break; } } if (!contains) { hostInfos.Add(hostInfo); cookie.m_key = "DANDANSERVERS"; cookie.m_value = JsonConvert.SerializeObject(hostInfos); DataCenter.UserCookieService.AddCookie(cookie); } String key2 = hostInfo.ToString(); OwLib.ChatService findChatService = DataCenter.GetClientChatService(key2); if (findChatService == null) { int socketID = OwLib.BaseService.Connect(hostInfo.m_ip, hostInfo.m_serverPort); if (socketID != -1) { OwLib.ChatService clientChatService = new OwLib.ChatService(); DataCenter.AddClientChatService(key2, clientChatService); OwLib.BaseService.AddService(clientChatService); clientChatService.Connected = true; clientChatService.ToServer = type == 1; //clientChatService.RegisterListener(DataCenter.ChatRequestID, new ListenerMessageCallBack(GintechMessageCallBack)); clientChatService.SocketID = socketID; clientChatService.Enter(); } } else { OwLib.ChatService clientChatService = DataCenter.GetClientChatService(key2); if (!clientChatService.Connected) { int socketID = OwLib.BaseService.Connect(hostInfo.m_ip, hostInfo.m_serverPort); if (socketID != -1) { clientChatService.Connected = true; clientChatService.SocketID = socketID; clientChatService.Enter(); } } } } } } } } SendToListener(message); }
/// <summary> /// 开始启动服务 /// </summary> public void StartConnect() { List <ChatHostInfo> hostInfos = new List <ChatHostInfo>(); UserCookie cookie = new UserCookie(); if (DataCenter.UserCookieService.GetCookie("DANDANSERVERS", ref cookie) > 0) { hostInfos = JsonConvert.DeserializeObject <List <ChatHostInfo> >(cookie.m_value); } else { if (DataCenter.HostInfo.m_defaultHost.Length > 0) { ChatHostInfo defaultHostInfo = new ChatHostInfo(); defaultHostInfo.m_ip = DataCenter.HostInfo.m_defaultHost; defaultHostInfo.m_serverPort = DataCenter.HostInfo.m_defaultPort; hostInfos.Add(defaultHostInfo); } } int hostInfosSize = hostInfos.Count; if (DataCenter.IsFull && hostInfosSize == 0) { ChatHostInfo defaultHostInfo = new ChatHostInfo(); defaultHostInfo.m_ip = "127.0.0.1"; defaultHostInfo.m_serverPort = 16666; hostInfos.Add(defaultHostInfo); } if (hostInfosSize > 0) { Random rd = new Random(); while (DataCenter.IsAppAlive()) { ChatHostInfo hostInfo = hostInfos[rd.Next(0, hostInfosSize)]; int socketID = OwLib.BaseService.Connect(hostInfo.m_ip, hostInfo.m_serverPort); if (socketID != -1) { String key = hostInfo.ToString(); if (m_mainForm != null) { m_mainForm.SetTitle(key); m_mainForm.BeginInvoke(new EventHandler(m_mainForm.SetTitle)); } Console.WriteLine(hostInfo.m_ip); OwLib.ChatService clientChatService = new OwLib.ChatService(); DataCenter.AddClientChatService(key, clientChatService); OwLib.BaseService.AddService(clientChatService); clientChatService.ToServer = true; clientChatService.Connected = true; if (!DataCenter.IsFull) { clientChatService.RegisterListener(DataCenter.ChatRequestID, new ListenerMessageCallBack(ChatMessageCallBack)); } clientChatService.SocketID = socketID; clientChatService.Enter(); m_isLogining = false; DataCenter.CheckConnects(); return; } } } }
/// <summary> /// 发送全体消息 /// </summary> private void SendAll() { byte[] fileBytes = null; RadioButtonA rbBarrage = GetRadioButton("rbBarrage"); RadioButtonA rbText = GetRadioButton("rbText"); RadioButtonA rbFile = GetRadioButton("rbFile"); RadioButtonA rbAttention = GetRadioButton("rbAttention"); String text = GetTextBox("txtSend").Text; String sayText = text; if (rbFile.Checked) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { text = "sendfile('" + new FileInfo(openFileDialog.FileName).Name + "');"; fileBytes = File.ReadAllBytes(openFileDialog.FileName); sayText = text; } else { return; } } else { if (text == null || text.Trim().Length == 0) { MessageBox.Show("请输入你想说的内容!", "提示"); } } if (rbBarrage.Checked) { text = "addbarrage('" + text + "');"; } else if (rbText.Checked) { text = "addtext('" + text + "');"; } else if (rbAttention.Checked) { text = "how('" + GetTextBox("txtUserName").Text + "喊:" + text + "');"; } ChatData chatData = new ChatData(); chatData.m_content = text; if (fileBytes != null) { chatData.m_body = fileBytes; chatData.m_bodyLength = fileBytes.Length; } chatData.m_from = DataCenter.UserName; DataCenter.SendAll(chatData); if (rbBarrage.Checked) { CIndicator indicator = CFunctionEx.CreateIndicator("", text, this); indicator.Clear(); indicator.Dispose(); } TextBoxA txtReceive = GetTextBox("txtReceive"); txtReceive.Text += "我说:\r\n" + sayText + "\r\n"; txtReceive.Invalidate(); if (txtReceive.VScrollBar != null && txtReceive.VScrollBar.Visible) { txtReceive.VScrollBar.ScrollToEnd(); txtReceive.Update(); txtReceive.Invalidate(); } }
/// <summary> /// 发送消息 /// </summary> private void Send(List <GridRow> rows) { byte[] fileBytes = null; String text = GetTextBox("txtSend").Text; RadioButtonA rbBarrage = GetRadioButton("rbBarrage"); RadioButtonA rbText = GetRadioButton("rbText"); RadioButtonA rbFile = GetRadioButton("rbFile"); RadioButtonA rbAttention = GetRadioButton("rbAttention"); String sayText = text; if (rbFile.Checked) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { text = "sendfile('" + new FileInfo(openFileDialog.FileName).Name + "');"; fileBytes = File.ReadAllBytes(openFileDialog.FileName); sayText = text; } else { return; } } else { if (text == null || text.Trim().Length == 0) { MessageBox.Show("请输入你想说的内容!", "提示"); } } if (rbBarrage.Checked) { text = "addbarrage('" + text + "');"; } else if (rbText.Checked) { text = "addtext('" + text + "');"; } else if (rbAttention.Checked) { text = "how('" + GetTextBox("txtUserName").Text + "喊:" + text + "');"; } int rowsSize = rows.Count; bool sendAll = false; if (rowsSize > 0) { for (int i = 0; i < rowsSize; i++) { GridRow thisRow = rows[i]; String ip = thisRow.GetCell("colP1").GetString(); int port = thisRow.GetCell("colP2").GetInt(); String userID = thisRow.GetCell("colP3").GetString(); ChatService chatService = null; String key = ip + ":" + CStr.ConvertIntToStr(port); chatService = DataCenter.GetClientChatService(key); if (chatService != null) { if (!chatService.Connected) { int socketID = OwLib.BaseService.Connect(ip, port); if (socketID != -1) { chatService.Connected = true; chatService.SocketID = socketID; chatService.Enter(); } else { sendAll = true; } } } else { int type = thisRow.GetCell("colP5").GetInt(); if (type == 1) { continue; } else { int socketID = OwLib.BaseService.Connect(ip, port); if (socketID != -1) { chatService = new ChatService(); chatService.SocketID = socketID; chatService.ServerIP = ip; chatService.ServerPort = port; chatService.ToServer = false; DataCenter.AddClientChatService(key, chatService); BaseService.AddService(chatService); } else { sendAll = true; } } } ChatData chatData = new ChatData(); chatData.m_content = text; if (fileBytes != null) { chatData.m_body = fileBytes; chatData.m_bodyLength = fileBytes.Length; } chatData.m_from = DataCenter.UserName; if (sendAll) { chatData.m_to = userID; DataCenter.SendAll(chatData); } else { chatService.Send(chatData); } if (rbBarrage.Checked) { CIndicator indicator = CFunctionEx.CreateIndicator("", text, this); indicator.Clear(); indicator.Dispose(); } TextBoxA txtReceive = GetTextBox("txtReceive"); txtReceive.Text += "我说:\r\n" + sayText + "\r\n"; txtReceive.Invalidate(); if (txtReceive.VScrollBar != null && txtReceive.VScrollBar.Visible) { txtReceive.VScrollBar.ScrollToEnd(); txtReceive.Update(); txtReceive.Invalidate(); } } } }
/// <summary> /// 调用主线程返方法 /// </summary> /// <param name="sender">调用者</param> /// <param name="args">参数</param> public void Invoke(object sender, object args) { CMessage message = args as CMessage; if (message != null) { if (message.m_serviceID == ChatService.SERVICEID_CHAT) { if (message.m_functionID == ChatService.FUNCTIONID_SENDALL) { ChatData chatData = new ChatData(); ChatService.GetChatData(chatData, message.m_body, message.m_bodyLength); CIndicator indicator = CFunctionEx.CreateIndicator2("", chatData, this); indicator.Clear(); indicator.Dispose(); } else if (message.m_functionID == ChatService.FUNCTIONID_GETHOSTS) { List <ChatHostInfo> datas = new List <ChatHostInfo>(); int type = 0; ChatService.GetHostInfos(datas, ref type, message.m_body, message.m_bodyLength); if (type != 2) { int datasSize = datas.Count; for (int i = 0; i < datasSize; i++) { ChatHostInfo hostInfo = datas[i]; List <GridRow> rows = m_gridHosts.m_rows; int rowsSize = rows.Count; bool containsRow = false; for (int j = 0; j < rowsSize; j++) { GridRow oldRow = rows[j]; if (oldRow.GetCell("colP1").GetString() == hostInfo.m_ip && oldRow.GetCell("colP2").GetInt() == hostInfo.m_serverPort) { containsRow = true; } } if (!containsRow) { if (hostInfo.m_type == 1) { String key = hostInfo.m_ip + ":" + hostInfo.m_serverPort; ChatService newServerService = DataCenter.GetClientChatService(key); if (newServerService == null) { newServerService = new ChatService(); newServerService.ServerIP = hostInfo.m_ip; newServerService.ServerPort = hostInfo.m_serverPort; newServerService.ToServer = true; BaseService.AddService(newServerService); DataCenter.AddClientChatService(key, newServerService); } } else { GridRow row = new GridRow(); m_gridHosts.AddRow(row); row.AddCell("colP1", new GridStringCell(hostInfo.m_ip)); row.AddCell("colP2", new GridIntCell(hostInfo.m_serverPort)); if (hostInfo.m_type == 1) { row.AddCell("colP3", new GridStringCell("--")); row.AddCell("colP4", new GridStringCell("--")); } else { row.AddCell("colP3", new GridStringCell(hostInfo.m_userID)); row.AddCell("colP4", new GridStringCell(hostInfo.m_userName)); } row.AddCell("colP5", new GridStringCell(hostInfo.m_type == 1 ? "服务器" : "客户端")); } } } } else { Dictionary <String, String> removeHosts = new Dictionary <String, String>(); foreach (ChatHostInfo hostInfo in datas) { removeHosts[hostInfo.ToString()] = ""; } List <GridRow> rows = m_gridHosts.m_rows; int rowsSize = rows.Count; if (rowsSize > 0) { for (int i = 0; i < rowsSize; i++) { GridRow row = rows[i]; String key = row.GetCell("colP1").GetString() + ":" + row.GetCell("colP2").GetString(); if (removeHosts.ContainsKey(key)) { m_gridHosts.RemoveRow(row); i--; rowsSize--; } } } } SetHostGridRowVisible(); } else if (message.m_functionID == ChatService.FUNCTIONID_SEND) { ChatData chatData = new ChatData(); ChatService.GetChatData(chatData, message.m_body, message.m_bodyLength); CIndicator indicator = CFunctionEx.CreateIndicator2("", chatData, this); indicator.Clear(); indicator.Dispose(); } } } String newStr = args as String; if (newStr != null) { if (newStr == "showchat") { FlashWindow(m_mainForm.Handle, true); SetForegroundWindow(m_mainForm.Handle); } else if (newStr == "shake") { m_mainForm.Play(); } else if (newStr.StartsWith("how:")) { String text = newStr.Substring(4); Barrage barrage = new Barrage(); barrage.Text = text; barrage.Mode = 1; m_barrageForm.BarrageDiv.AddBarrage(barrage); } else { TextBoxA txtReceive = GetTextBox("txtReceive"); txtReceive.Text += newStr; txtReceive.Invalidate(); if (txtReceive.VScrollBar != null && txtReceive.VScrollBar.Visible) { txtReceive.VScrollBar.ScrollToEnd(); txtReceive.Update(); txtReceive.Invalidate(); } } } }
/// <summary> /// 保存组信息 /// </summary> /// <param name="groups">组列表</param> public static void SaveGroups(List <ChatGroup> groups) { String file = DataCenter.GetAppPath() + "\\groups.txt"; CFileA.Write(file, JsonConvert.SerializeObject(groups)); }
/// <summary> /// 点击事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击次数</param> /// <param name="delta">滚轮值/param> private void ClickEvent(object sender, POINT mp, MouseButtonsA button, int clicks, int delta) { if (button == MouseButtonsA.Left && clicks == 1) { ControlA control = sender as ControlA; String name = control.Name; if (name == "AA") { DimensionWindow performanceWindow = new DimensionWindow(Native); performanceWindow.ShowDialog(); } else if (name == "AOA") { StaffWindow staffWindow = new StaffWindow(Native); staffWindow.ShowDialog(); } else if (name == "AAM") { ProjectWindow projectWindow = new ProjectWindow(Native); projectWindow.ShowDialog(); } else if (name == "AI") { AwardWindow awardWindow = new AwardWindow(Native); awardWindow.ShowDialog(); } else if (name == "BAR") { CalendarWindow calendarWindow = new CalendarWindow(Native); calendarWindow.ShowDialog(); } else if (name == "CA") { MasterWindow masterWindow = new MasterWindow(Native); masterWindow.ShowDialog(); } else if (name == "CCM") { GitWindow gitWindow = new GitWindow(Native); gitWindow.ShowDialog(); } else if (name == "COI") { ServerWindow serverWindow = new ServerWindow(Native); serverWindow.ShowDialog(); } else if (name == "GTM") { ClueWindow clueWindow = new ClueWindow(Native); clueWindow.ShowDialog(); } else if (name == "IAC") { PersonalWindow personalWindow = new PersonalWindow(Native); personalWindow.ShowDialog(); } else if (name == "LP") { OpinionWindow opinionWindow = new OpinionWindow(Native); opinionWindow.ShowDialog(); } else if (name == "OI") { FollowWindow followWindow = new FollowWindow(Native); followWindow.ShowDialog(); } else if (name == "PH") { RemoteWindow remoteWindow = new RemoteWindow(Native); remoteWindow.ShowDialog(); } else if (name == "RI") { JidianWindow jidianWindow = new JidianWindow(Native); jidianWindow.ShowDialog(); } else if (name == "TC") { Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = DataCenter.GetAppPath() + "\\iTeam.exe"; startInfo.Arguments = "-plan"; process.StartInfo = startInfo; process.Start(); } else if (name == "UA") { LevelWindow levelWindow = new LevelWindow(Native); levelWindow.ShowDialog(); } else if (name == "UIM") { WindowXmlEx skyWindow = new WindowXmlEx(); skyWindow.Load(Native, "SkyWindow", "skyWindow"); skyWindow.ShowDialog(); } else if (name == "BS") { BSStockWindow bsStockWindow = new BSStockWindow(Native); bsStockWindow.ShowDialog(); } else if (name == "RP") { ExamWindow reportWindow = new ExamWindow(Native); reportWindow.ShowDialog(); } else if (name == "BC") { BusinessCardWindow businessCardWindow = new BusinessCardWindow(Native); businessCardWindow.ShowDialog(); } else if (name == "OW") { DialogWindow dialogWindow = new DialogWindow(Native); dialogWindow.ShowDialog(); } } }
/// <summary> /// 数据落地线程工作 /// </summary> public static void StartWork3() { //复制数据 LoadHistoryDatas(); GetMinuteDatas(); //新旧数据合并 foreach (String oCode in m_historyDatas.Keys) { if (!m_latestDatas.ContainsKey(oCode) || !m_historyDatas.ContainsKey(oCode)) { continue; } SecurityLatestData securityLatestData = m_latestDatas[oCode]; List <SecurityData> oldSecurityDatas = m_historyDatas[oCode]; SecurityData oldSecurityData = oldSecurityDatas[oldSecurityDatas.Count - 1]; int myear = 0, mmonth = 0, mday = 0, mhour = 0, mmin = 0, msec = 0, mmsec = 0; CStrA.M130(oldSecurityData.m_date, ref myear, ref mmonth, ref mday, ref mhour, ref mmin, ref msec, ref mmsec); int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, msec2 = 0; CStrA.M130(securityLatestData.m_date, ref year, ref month, ref day, ref hour, ref min, ref sec, ref msec2); if (year >= myear && month >= mmonth && day >= mday) { SecurityData nSecurityData = new SecurityData(); nSecurityData.m_amount = securityLatestData.m_amount; nSecurityData.m_close = securityLatestData.m_close; nSecurityData.m_date = securityLatestData.m_date; nSecurityData.m_high = securityLatestData.m_high; nSecurityData.m_low = securityLatestData.m_low; nSecurityData.m_open = securityLatestData.m_open; nSecurityData.m_volume = securityLatestData.m_volume; if (day == mday) { m_historyDatas[oCode].RemoveAt(m_historyDatas[oCode].Count - 1); } m_historyDatas[oCode].Add(nSecurityData); } } String outputFileTemplate = DataCenter.GetAppPath() + "\\day\\{0}.txt"; String fileInfo = "{0} {1} 日线 前复权\r\n"; String title = " 日期 开盘 最高 最低 收盘 成交量 成交额\r\n"; String lineTemp = "{0},{1},{2},{3},{4},{5},{6}\r\n"; String timeFormatStr = "yyyy-MM-dd"; //写入文件 foreach (String code in m_historyDatas.Keys) { List <SecurityData> temp3 = m_historyDatas[code]; StringBuilder strbuff = new StringBuilder(); strbuff.Append(String.Format(fileInfo, m_codedMap[code].m_code, m_codedMap[code].m_name)); strbuff.Append(title); foreach (SecurityData sdt in temp3) { strbuff.Append(String.Format(lineTemp, // CStr.ConvertNumToDate(sdt.m_date).ToString(timeFormatStr), // sdt.m_open, // sdt.m_high, // sdt.m_low, // sdt.m_close, // sdt.m_volume, // sdt.m_amount)); } strbuff.Append("数据来源:通达信\r\n"); CFileA.Write(String.Format(outputFileTemplate, code), strbuff.ToString()); } }
/// <summary> /// 切换问题 /// </summary> public void ChangeQuestion() { if (m_currentQuestion != null) { m_answers[m_currentQuestion.m_title] = m_txtAnswer.Text; } if (m_currentQuestion != null && (m_currentQuestion.m_type == "记忆" || m_currentQuestion.m_type == "算数")) { if (m_currentQuestion.m_answer != m_txtAnswer.Text) { for (int i = 0; i < 5; i++) { AddBarrage("回答错误", 0, 4 + i); } } } m_txtAnswer.ReadOnly = false; if (m_btnStart.Text == "开始") { Thread thread = new Thread(new ThreadStart(CheckResult)); thread.Start(); //加载问题 String file = DataCenter.GetAppPath() + "\\Exam.txt"; if (GetRadioButton("rbExamC").Checked) { file = DataCenter.GetAppPath() + "\\Exam_cplusplus.txt"; } else if (GetRadioButton("rbExamJava").Checked) { file = DataCenter.GetAppPath() + "\\Exam_Java.txt"; } String content = ""; CFileA.Read(file, ref content); String[] strs = content.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; for (int i = 0; i < strsSize; i++) { String str = strs[i]; QuestionInfo question = new QuestionInfo(); int idx = str.IndexOf(","); question.m_type = str.Substring(0, idx); int nIdx = str.IndexOf(",", idx + 1); question.m_interval = Convert.ToInt32(str.Substring(idx + 1, nIdx - idx - 1)); question.m_title = str.Substring(nIdx + 1); m_oldQuestions.Add(question); } m_bulletTime = DateTime.Now; for (int i = 0; i < 10; i++) { AddBarrage("开始答题", 0, 4 + i); } GetDiv("divMode").Enabled = false; GetDiv("divMode").CanFocus = false; switch (m_lblMode.Text) { case "初级": m_mode = 0; break; case "中级": m_mode = 1; break; case "高级": m_mode = 2; break; case "英雄": m_mode = 3; break; case "史诗": m_mode = 4; break; case "传说": m_mode = 5; break; } if (m_mode == 5) { GetButton("btnTimer").BackImage = "skull.jpg"; GetButton("btnAnswer").BackImage = "me.jpg"; GetButton("btnQuestion").BackImage = "you.jpg"; ButtonA choose1 = GetButton("choose1"); ButtonA choose2 = GetButton("choose2"); ButtonA choose3 = GetButton("choose3"); ButtonA choose4 = GetButton("choose4"); ButtonA choose5 = GetButton("choose5"); ButtonA choose6 = GetButton("choose6"); choose1.BackImage = "a1.jpg"; choose2.BackImage = "a2.jpg"; choose3.BackImage = "a3.jpg"; choose4.BackImage = "a4.jpg"; choose5.BackImage = "a5.jpg"; choose6.BackImage = "a6.jpg"; for (int i = 0; i < 20; i++) { CometA comet = new CometA(); Native.AddControl(comet); } m_txtAnswer.BorderColor = COLOR.ARGB(200, 0, 0); m_txtQuestion.BorderColor = COLOR.ARGB(200, 0, 0); } m_firstTime = DateTime.Now; bool lastState = true; if (m_isMatch) { for (int i = 0; i < 100; i++) { QuestionInfo codingQuestion = new QuestionInfo(); codingQuestion.m_type = "极限"; codingQuestion.m_interval = 180; codingQuestion.m_title = "以你最快的速度连续输出for(int i = 0; i < 100; i++)(前任select * from冠军是吴思杰,目前30次为合格)"; m_questions.Add(codingQuestion); } } else { while (m_oldQuestions.Count > 0) { QuestionInfo question = m_oldQuestions[m_rd.Next(0, m_oldQuestions.Count)]; if (lastState) { if (question.m_type == "打字") { m_questions.Add(question); m_oldQuestions.Remove(question); int random = m_rd.Next(0, 5); //加减运算 //if (random == 0) //{ // QuestionInfo addSubQuestion = new QuestionInfo(); // addSubQuestion.m_type = "算数"; // addSubQuestion.m_interval = 30; // int count = 5; // String num1 = GetRandomNum(count); // String num2 = GetRandomNum(count); // String op = "+"; // addSubQuestion.m_title = num1 + op + num2; // addSubQuestion.m_answer = (CStr.ConvertStrToInt(num1) + CStr.ConvertStrToInt(num2)).ToString(); // m_questions.Add(addSubQuestion); //} ////记忆考察 //else if (m_mode != 5 && random == 1) //{ // QuestionInfo memoryQuestion = new QuestionInfo(); // memoryQuestion.m_type = "记忆"; // memoryQuestion.m_interval = 30; // int count = 11; // String num = GetRandomNum(count); // memoryQuestion.m_title = num; // memoryQuestion.m_answer = num; // m_questions.Add(memoryQuestion); //} //if (m_questions.Count >= 6 && coding) //{ // QuestionInfo codingQuestion = new QuestionInfo(); // codingQuestion.m_type = "极限"; // codingQuestion.m_interval = 180; // codingQuestion.m_title = "以你最快的速度连续输出for(int i = 0; i < 100; i++)(前任select * from冠军是吴思杰,目前30次为合格)"; // m_questions.Add(codingQuestion); // coding = false; //} lastState = false; } } else { if (question.m_type == "口述") { m_questions.Add(question); m_oldQuestions.Remove(question); lastState = true; } } bool noDZ = true, noKS = true; int oldQuestionsSize = m_oldQuestions.Count; for (int i = 0; i < oldQuestionsSize; i++) { if (m_oldQuestions[i].m_type == "口述") { noKS = false; } else if (m_oldQuestions[i].m_type == "打字") { noDZ = false; } } if (noDZ || noKS) { break; } } } } m_btnStart.Text = "下一题"; if (m_questions.Count > 0) { m_currentQuestion = m_questions[0]; if (m_currentQuestion.m_type != "口述") { m_txtAnswer.Text = ""; } else { m_txtAnswer.Text = "请口述"; m_txtAnswer.Text = ""; } m_currentTick = m_currentQuestion.m_interval; if (m_currentQuestion.m_type == "口述") { switch (m_mode) { case 0: m_currentTick *= 2; break; case 1: break; case 2: m_currentTick = m_currentQuestion.m_interval * 2 / 3; break; case 3: m_currentTick = m_currentQuestion.m_interval / 2; break; case 4: m_currentTick = m_currentQuestion.m_interval / 3; break; case 5: m_currentTick = 2; m_txtAnswer.Text = "请在打字题中回答"; break; } } else if (m_currentQuestion.m_type == "打字") { switch (m_mode) { case 0: m_currentTick *= 2; break; case 1: break; case 2: m_currentTick = m_currentQuestion.m_interval * 2 / 3; break; case 3: m_currentTick = m_currentQuestion.m_interval / 2; break; case 4: m_currentTick = m_currentQuestion.m_interval / 3; break; case 5: m_currentTick = m_currentQuestion.m_interval / 3; break; } } else if (m_currentQuestion.m_type == "算数") { switch (m_mode) { case 2: m_currentTick = 25; break; case 3: m_currentTick = 20; break; case 4: m_currentTick = 15; break; case 5: m_currentTick = 10; break; } } else if (m_currentQuestion.m_type == "记忆") { m_txtAnswer.Text = "请迅速记忆上面这串数字,在此文字消失时打出刚才那串数字"; m_txtAnswer.ReadOnly = true; switch (m_mode) { case 0: m_currentTick = 40; break; case 1: m_currentTick = 30; break; case 2: m_currentTick = 28; break; case 3: m_currentTick = 26; break; case 4: m_currentTick = 24; break; case 5: m_currentTick = 20; break; } } m_count++; m_lblAlarm.Text = "已做" + m_count.ToString() + "题"; m_totalTick = m_currentTick; double finishTime = (double)((TimeSpan)(DateTime.Now - m_firstTime)).TotalMilliseconds / 1000; m_lblTime.Text = "还剩" + m_totalTick.ToString("0.00") + "秒 已用时" + finishTime.ToString("0.00") + "秒"; m_questions.Remove(m_currentQuestion); m_txtQuestion.Text = m_currentQuestion.m_title; if (m_currentQuestion.m_type == "口述") { m_lblType.Text = "题型:打字,限时" + m_currentTick.ToString() + "秒"; } else { m_lblType.Text = "题型:" + m_currentQuestion.m_type + ",限时" + m_currentTick.ToString() + "秒"; } } }