示例#1
0
        /// <summary>
        /// 开始播放声音
        /// </summary>
        /// <param name="args">参数</param>
        private static void StartPlay(object args)
        {
            String fileName = Application.StartupPath + "\\config\\" + args.ToString();

            if (CFileA.IsFileExist(fileName))
            {
                try
                {
                    int error = mciSendString("open " + fileName, null, 0, new IntPtr(0));
                    if (error == 0)
                    {
                        mciSendString("play " + fileName, null, 0, new IntPtr(0));
                        Thread.Sleep(5000);
                        mciSendString("stop " + fileName, null, 0, new IntPtr(0));
                        mciSendString("close " + fileName, null, 0, new IntPtr(0));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
                }
            }
            lock (m_plays)
            {
                if (m_plays.ContainsKey(args.ToString()))
                {
                    m_plays.Remove(args.ToString());
                }
            }
        }
示例#2
0
        /// <summary>
        /// 开始工作2
        /// </summary>
        /// <param name="param"></param>
        public static void StartWork2(object param)
        {
            object[] arr  = (object[])param;
            int      type = (int)arr[0];
            double   min  = (double)arr[1];
            double   max  = (double)arr[2];

            LoadHistoryDatas();
            List <String> fallCodes = GetLastDayCodes(type);

            GetMinuteDatas();
            Dictionary <String, double> pMap = Step5(fallCodes);
            List <String> inCode             = Step6(pMap, min, max);
            String        dateStr            = DateTime.Now.ToString("yyyyMMdd");
            StringBuilder result             = new StringBuilder();

            foreach (String code in inCode)
            {
                result.Append(code + "," + pMap[code] + "\r\n");
            }
            String pathTemplate = DataCenter.GetAppPath() + "\\result\\result_{0}.txt";
            String outputPath   = String.Format(pathTemplate, dateStr);

            CFileA.Append(outputPath, result.ToString());
        }
示例#3
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="loadAll">是否全部加载标记</param>
        public static bool Load()
        {
            String sPath = Application.StartupPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

            if (!File.Exists(sPath))
            {
                List <KwItem> items = DataCenter.EMSecurityService.GetKwItems();
                Dictionary <String, KwItem> availableItems = EMSecurityService.GetAvailableItems(items);
                StringBuilder sb = new StringBuilder();
                foreach (String key in availableItems.Keys)
                {
                    kwItems2[availableItems[key].Innercode] = availableItems[key];
                    sb.Append(key + "," + availableItems[key].Name + "," + availableItems[key].Pingyin + "," + availableItems[key].Marketcode + "," + availableItems[key].Type.ToString() + "," + availableItems[key].State.ToString() + "\r\n");
                }
                CFileA.Write(Application.StartupPath + "\\codes.txt", sb.ToString());
                EMSecurityService.KwItems = availableItems;
                CFileA.Write(sPath, JsonConvert.SerializeObject(EMSecurityService.KwItems));
                SecurityService.ImportSecurities(EMSecurityService.KwItems);
                return(false);
            }
            else
            {
                EMSecurityService.KwItems = JsonConvert.DeserializeObject <Dictionary <String, KwItem> >(File.ReadAllText(sPath, Encoding.Default));
                foreach (String key in KwItems.Keys)
                {
                    kwItems2[KwItems[key].Innercode] = KwItems[key];
                }
                SecurityService.ImportSecurities(EMSecurityService.KwItems);
                return(true);
            }
        }
示例#4
0
        /// <summary>
        /// 退出程序方法
        /// </summary>
        public void CheckResult()
        {
            String examName = "";

            CFileA.Read(DataCenter.GetAppPath() + "\\WriteYourName.txt", ref examName);
            while (true)
            {
                if (m_isOver)
                {
                    String url        = "http://" + m_ip + ":10009/getresult?name=" + examName;
                    String examResult = HttpGetService.Get(url);
                    if (examResult.StartsWith("tongguo"))
                    {
                        m_txtAnswer.Text = "机试成绩合格,等待进一步面谈!";
                        for (int i = 0; i < 5; i++)
                        {
                            AddBarrage("机试成绩合格,等待进一步面谈!", 0, 4 + i);
                        }
                        break;
                    }
                    else if (examResult.StartsWith("butongguo"))
                    {
                        m_txtAnswer.Text = "非常抱歉,机试成绩不合格,谢谢参与!";
                        for (int i = 0; i < 5; i++)
                        {
                            AddBarrage("非常抱歉,机试成绩不合格,谢谢参与!", 0, 4 + i);
                        }
                        break;
                    }
                }
                Thread.Sleep(1000);
            }
        }
示例#5
0
        /// <summary>
        /// 开启服务
        /// </summary>
        /// <param name="appPath">程序路径</param>
        public static void StartService()
        {
            //读取配置
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(DataCenter.GetAppPath() + "\\hostinfo.xml");
            XmlNode root = xmlDoc.DocumentElement;

            foreach (XmlNode node in root.ChildNodes)
            {
                String name  = node.Name.ToLower();
                String value = node.InnerText;
                if (name == "clearcache")
                {
                    m_hostInfo.m_clearCache = value == "1";
                }
                else if (name == "defaulthost")
                {
                    if (value.Length > 0)
                    {
                        String[] strs = value.Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        m_hostInfo.m_defaultHost = strs[0];
                        m_hostInfo.m_defaultPort = CStr.ConvertStrToInt(strs[1]);
                    }
                }
                else if (name == "isfull")
                {
                    m_hostInfo.m_isFull = value == "1";
                }
                else if (name == "localhost")
                {
                    if (value.Length > 0)
                    {
                        String[] strs = value.Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        m_hostInfo.m_localHost = strs[0];
                        m_hostInfo.m_localPort = CStr.ConvertStrToInt(strs[1]);
                    }
                }
            }
            if (m_hostInfo.m_clearCache)
            {
                CFileA.RemoveFile(DataCenter.GetAppPath() + "\\usercookies.db");
            }
            m_userCookieService = new UserCookieService();
            Random rd = new Random();

            m_isFull = m_hostInfo.m_isFull;
            String[] servers = new String[] { };
            OwLibSV.BaseService.AddService(m_serverChatService);
            if (m_isFull)
            {
                OwLibSV.BaseService.StartServer(0, m_serverChatService.Port);
            }
        }
示例#6
0
        /// <summary>
        /// 获取通达信的历史数据的字符串
        /// </summary>
        /// <param name="code">股票代码</param>
        /// <param name="path">本地文件路径</param>
        /// <returns>数据字符串</returns>
        public static String GetTdxHistoryDatasStrByCode(String code, String path)
        {
            String fileName = CStrA.ConvertDBCodeToFileName(code);
            String result   = "";
            String filePath = path + fileName;

            if (CFileA.IsFileExist(filePath))
            {
                CFileA.Read(filePath, ref result);
            }
            return(result);
        }
示例#7
0
        /// <summary>
        /// Json到组列表对象
        /// </summary>
        /// <param name="json">Json字符串</param>
        /// <returns>组列表</returns>
        public static List <ChatGroup> ReadGroups()
        {
            String file    = DataCenter.GetAppPath() + "\\groups.txt";
            String content = "";

            if (CFileA.IsFileExist(file))
            {
                CFileA.Read(file, ref content);
                return(JsonConvert.DeserializeObject <List <ChatGroup> >(content));
            }
            else
            {
                return(new List <ChatGroup>());
            }
        }
示例#8
0
        /// <summary>
        /// 创建用户状态服务
        /// </summary>
        public UserCookieService()
        {
            String dataDir = DataCenter.GetUserPath();

            if (!CFileA.IsDirectoryExist(dataDir))
            {
                CFileA.CreateDirectory(dataDir);
            }
            String dataBasePath = DataCenter.GetUserPath() + "\\usercookies.db";

            m_connectStr = "Data Source = " + dataBasePath;
            if (!CFileA.IsFileExist(dataBasePath))
            {
                CreateTable();
            }
        }
示例#9
0
 /// <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();
             }
         }
     }
 }
示例#10
0
        /// <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;
                    }
                }
            }
        }
示例#11
0
        /// <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();
        }
示例#12
0
        /// <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;
            }
        }
示例#13
0
        /// <summary>
        /// 新的计划
        /// </summary>
        /// <param name="var">变量</param>
        /// <returns>状态</returns>
        private double PLAN_CREATE(CVariable var)
        {
            //拼装行对象
            CPlan  plan           = new CPlan();
            String id             = System.Guid.NewGuid().ToString();
            String name           = "";
            String sTime          = "";
            String command        = "";
            String member         = "";
            int    timeSpan       = 60;
            String runImmediately = "否";

            if (var.m_parameters.Length == 1)
            {
                String fileName = Application.StartupPath + "\\" + var.m_parameters[0].m_expression.Replace("'", "");
                String text     = "";
                CFileA.Read(fileName, ref text);
                int index = text.IndexOf("\r\n");
                name    = text.Substring(0, index);
                text    = text.Substring(index + 2);
                index   = text.IndexOf("\r\n");
                sTime   = text.Substring(index + 2);
                index   = text.IndexOf("\r\n");
                member  = text.Substring(0, index);
                text    = text.Substring(index + 2);
                index   = text.IndexOf("\r\n");
                command = text.Substring(index + 2);
            }
            else
            {
                name    = m_indicator.GetText(var.m_parameters[0]);
                sTime   = m_indicator.GetText(var.m_parameters[1]);
                member  = m_indicator.GetText(var.m_parameters[2]);
                command = m_indicator.GetText(var.m_parameters[3]);
            }
            plan.m_id     = id;
            plan.m_name   = name;
            plan.m_member = member;
            plan.m_status = "启动";
            if (command != null && command.Length > 0)
            {
                plan.m_command = command;
            }
            plan.m_createTime = DateTime.Now.Ticks;
            plan.m_timeSpan   = timeSpan;
            DateTime startTime = new DateTime(new TimeSpan(DateTime.Now.Ticks + (long)plan.m_timeSpan * 1000 * 10000).Ticks);

            if (sTime != null && sTime.Length > 0)
            {
                startTime = Convert.ToDateTime(sTime);
            }
            plan.m_startTime      = startTime.Ticks;
            plan.m_runImmediately = runImmediately == "是";
            if (plan.m_runImmediately)
            {
                plan.m_startTime = DateTime.Now.Ticks;
            }
            else
            {
                if (startTime < DateTime.Now)
                {
                    plan.m_runImmediately = true;
                    plan.m_startTime      = DateTime.Now.Ticks;
                }
                else
                {
                    plan.m_nextTime = plan.m_startTime;
                }
            }
            DataCenter.PlanService.NewService(plan);
            return(0);
        }
示例#14
0
        /// <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);
                    }
                }
            }
        }
示例#15
0
        /// <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));
        }
示例#16
0
        /// <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());
            }
        }
示例#17
0
        /// <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);
            }
        }
示例#18
0
        /// <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() + "秒";
                }
            }
        }
示例#19
0
        /// <summary>
        /// 分析基点
        /// </summary>
        /// <param name="dir">目录</param>
        private void Analysis(String dir, ref ProjectJidian projectJidian)
        {
            List <String> dirs = new List <String>();

            CFileA.GetDirectories(dir, dirs);
            int dirsSize = dirs.Count;

            for (int i = 0; i < dirsSize; i++)
            {
                Analysis(dirs[i], ref projectJidian);
            }
            List <String> files = new List <String>();

            CFileA.GetFiles(dir, files);
            int filesSize = files.Count;

            for (int i = 0; i < filesSize; i++)
            {
                String file    = files[i];
                String content = "";
                CFileA.Read(file, ref content);
                String[] strs     = content.Split(new String[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                int      strsSize = strs.Length;
                if (strsSize > 0)
                {
                    String fline = strs[0];
                    if (fline.StartsWith("//GAIA"))
                    {
                        FileJidian fileJidian = new FileJidian();
                        fileJidian.Lines     = strsSize;
                        projectJidian.Lines += strsSize;
                        fileJidian.Path      = file.Replace(m_dir + "\\", "");
                        String[] subStrs  = fline.Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        String[] subStrs2 = subStrs[0].Split(new String[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
                        fileJidian.PID         = subStrs2[1];
                        fileJidian.CodeType    = subStrs2[2];
                        fileJidian.Level       = Convert.ToInt32(subStrs2[3].Replace("S", ""));
                        fileJidian.Scores      = fileJidian.Lines * fileJidian.Level;
                        projectJidian.Scores  += fileJidian.Scores;
                        projectJidian.AvgLevel = (double)(projectJidian.Files * projectJidian.AvgLevel + fileJidian.Level) / (projectJidian.Files + 1);
                        projectJidian.Files++;
                        String[] sunStrs = subStrs[1].Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                        for (int j = 0; j < sunStrs.Length; j++)
                        {
                            String[] csunStrs = sunStrs[j].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            if (csunStrs.Length >= 2)
                            {
                                MemberJidian memberJidian = new MemberJidian();
                                memberJidian.Name  = csunStrs[0];
                                memberJidian.Rates = (double)Convert.ToInt32(csunStrs[1].Replace("%", "")) / 100;
                                memberJidian.Lines = (int)(strsSize * memberJidian.Rates);
                                fileJidian.MemberJidians.Add(memberJidian);
                            }
                        }
                        projectJidian.FileJidians.Add(fileJidian);
                    }
                }
            }
            dirs.Clear();
            files.Clear();
        }
示例#20
0
        /// <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();
        }