Esempio n. 1
0
// ---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender) {
	// using namespace std;
	/*
	regex expression("\\s+href\\s*=\\s*\"([^\"]*)\"",regbase::normal|regbase::icase);
	std::string ss="<a href=\"index.html\"><img src=\"logo.gif\"></a>";
	std::deque<std::string> result;
	regex_split(std::back_inserter(result),ss,expression);
	 */
	/*
	copy(result.begin(),result.end(),ostream_iterator<string>(cout,"\n"));
	int c;
	cin>>c;
	 */
//	LogServerI lpLogserver;
//	char* lpszRunInfo = "null";
//	lpLogserver.main(0, &lpszRunInfo, "config.server");
	//
	AnsiString s;
	s = Now().CurrentDate().DateString();
	// 初始化  系统参数

	AnsiString strBakLogIP;
	AnsiString strBakLogDB;
	AnsiString strBakLogUid;
	AnsiString strBakLogPw;

	WideString filename = "./monitor.xml";
	TXMLDocument* xmldoc = new TXMLDocument(this);
	xmldoc->FileName = filename;
	xmldoc->Active = true;
	_di_IXMLNode node = xmldoc->DocumentElement;
	_di_IXMLNodeList nodes = node->ChildNodes;
	int n;
	_server.ip = "server";
	System::MkDir(_server.ip);
	_server.logfile = _server.ip + "/" + Now().CurrentDate().DateString()
	+ ".log";
	// _server.fpstore = fopen( _server.logfile.c_str(),"a+");
	_server.fpstore = CreateFile(_server.logfile.c_str(), GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
		FILE_ATTRIBUTE_NORMAL, NULL);
	for (n = 0; n < nodes->Count; n++) {
		node = nodes->Nodes[n];

		if (node->GetNodeName() == "server") {
			s = node->GetAttribute("port");
			_serverport = s.ToInt();
			this->udpServer->DefaultPort = _serverport;
			udpServer->Active = true;
			initAlertFilter(_server.filter, node);
		}
		else if (node->GetNodeName() == "robot") {
			_robotport = node->GetAttribute("port");
			/**
			 * chenlsh modified on 2010-03-17
			 * for IOCP server initializing
			 */
			m_server.Init(TForm1::ProcessRecvData, _robotport);
			_rebotport2 = node->GetAttribute("port2");
			udpRobot2->DefaultPort = _rebotport2;
			udpRobot2->Active = true;
		}
		else if (node->GetNodeName() == "bakLogServer") {
			/**
			 * chenlsh modified on 2010-03-17
			 * for IOCP server initializing
			 */
			strBakLogIP = node->GetAttribute("ip");
			strBakLogDB = node->GetAttribute("catalog");
			strBakLogUid = node->GetAttribute("userId");
			strBakLogPw = node->GetAttribute("pw");

		}
		else if (node->GetNodeName() == "offline_interval") {
			_offline_interval = node->GetNodeValue();
		}
		else if (node->GetNodeName() == "buffer_lines") {
			_buffer_lines = node->GetNodeValue();
		}

		///初始化设备清单
		if (node->GetNodeName() == "robots") {
			_di_IXMLNodeList nodelist;
			nodelist = node->GetChildNodes();
			int count = nodelist->GetCount();
			for (int m = 0; m < nodelist->GetCount(); m++) {
				node = nodelist->Nodes[m];
				if (node->GetNodeName() == "group") {
					RobotGroup group;
					int ii;
					group.name = node->GetAttribute("name");
					_di_IXMLNodeList node_robots;
					node_robots = node->GetChildNodes();
					for (ii = 0; ii < node_robots->GetCount(); ii++) {
						_di_IXMLNode nodeRobot;
						nodeRobot = node_robots->Nodes[ii];
						GtrRobot* lpRobot = new GtrRobot();
						if (nodeRobot->GetNodeName() == "robot") {
							lpRobot->name = nodeRobot->GetAttribute("name");
							lpRobot->ip = nodeRobot->GetAttribute("ip");
							if (nodeRobot->HasAttribute("gamepath")) {
								lpRobot->gamepath = nodeRobot->GetAttribute
								("gamepath");
							}
							else {
								ShowMessage
								("错误:游戏主机" + lpRobot->ip +
									"未定义游戏目录!");
								// return;
							}
							System::MkDir(lpRobot->ip);
							// if (robot.ip == "192.168.67.19") {
							// int x = 0;
							// }

							lpRobot->logfile = lpRobot->ip + "\\" + Now()
							.CurrentDate().DateString() + ".log";
							// nodeRobot->GetAttribute("logfile");
							// robot.fpstore = fopen(robot.logfile.c_str(),"a+");
							lpRobot->fpstore = CreateFile
							(lpRobot->logfile.c_str(), GENERIC_WRITE,
								FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
								OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
							initAlertFilter(lpRobot->filter, nodeRobot);
							// regular express <regex/>

							/**
							 * Chenlsh added 2010-03-26
							 * ip地址对应机器人
							 */
							group.robots.push_back(lpRobot);
							LPROBOTDATAMISC lpRobotDataMisc = new ROBOTDATAMISC;
							lpRobotDataMisc->lpRobot = lpRobot;
							_robotMap.insert(std::map<AnsiString,
								LPROBOTDATAMISC>::value_type(lpRobot->ip,
									lpRobotDataMisc));
						}
					}
					_robotGroups.push_back(group);
				}
			}
		}
	}
	TTreeNode * treeroot = treeRobotGroup->Items->GetFirstNode();
	for (int n = 0; n < _robotGroups.size(); n++) {
		TTreeNode * newnode = treeRobotGroup->Items->AddChild(treeroot,
			_robotGroups[n].name); // _robotGroups
		newnode->Data = (void*) & _robotGroups[n];
	}

	/// Timer open
	timerStatus->Enabled = true;

	/**
	* 开启ICE LogServer
	*/
	DWORD dwThreadID = 0;
	CloseHandle( CreateThread(NULL, 0,ThreadProc, NULL, 0, &dwThreadID) );

	/**
	 * 定义数据库相关属性
	 */
	WideString strConn =
	"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=";
	strConn += strBakLogUid;
	strConn += ";Password="******";Initial Catalog=";
	strConn += strBakLogDB;
	strConn += ";Data Source=";
	strConn += strBakLogIP;

	this->_lpAdoConn->ConnectionString = strConn;
	this->_lpAdoConn->ConnectionTimeout = 30;
	this->_lpAdoConn->Connected = true;

  //	this->_alertForm = new TAlertForm(this);

  //  this->_alertForm->Show();

	/**
	 * 使用数据库时的互斥量初始化
	 */

	//InitializeCriticalSection(&g_cs);

}
Esempio n. 2
0
void __fastcall TFormReportBULast2::ProcessPlan(AnsiString year)
{
    AnsiString query;

    // зададим даты для расчета долга в предыдущем периоде 2009-2010
    query = "SET @date_pre1 = '" + year + "-02-01'";                        // 2009-02-01
    mysql_query(mysql, query.c_str());
    query = "SET @date_pre2 = '" + year + "-09-01'";                        // 2009-09-01
    mysql_query(mysql, query.c_str());
    query = "SET @date_pre3 = '" + AnsiString(year.ToInt()+1) + "-02-01'";  // 2010-02-01

    // соберем оплаты по каждой категории
    mysql_query(mysql, "drop temporary table if exists old_pay");
    mysql_query(mysql,
        "CREATE TEMPORARY TABLE old_pay "
        " ( "
        "  id        int(11) NOT NULL AUTO_INCREMENT, "
        "  idstud    int(11) NOT NULL, "
        "  idopt     int(11) NOT NULL, "
        "  plan      int(11) NOT NULL, "
        "  pay       int(11) NOT NULL, "
        "  INDEX (id),     "
        "  INDEX (idstud)  "
        " ) TYPE = HEAP ");

    //# это обычная сентябрьская оплата
    mysql_query(mysql,"INSERT old_pay (idstud, idopt, plan, pay)                                    "
          " SELECT s.idstud, s.idopt, s.commoncountmoney, SUM(COALESCE(fact.moneypay, 0))           "
          " FROM (                                                                                  "
          "      SELECT st.id as idstud, opts.id as idopt, opts.commoncountmoney                    "
          "      FROM students AS st, payoptstest as opts, voc as v                                 "
          "      WHERE st.deleted = 0 AND opts.deleted = 0 AND v.deleted = 0                        "
          "      AND v.vkey = 'grp'  AND st.grpid = v.num AND opts.idgroup = st.grpid               "
          "      AND opts.datestart=@date_pre2 AND st.cityid != 0                                   "
          " ) as s                                                                                  "
          " LEFT JOIN payfactstest AS fact                                                          "
          " ON s.idopt = fact.idopts AND s.idstud = fact.idstud AND fact.deleted = 0                "
          " GROUP BY s.idstud, s.idopt");

    //# это февральские предыдущие
    mysql_query(mysql,"INSERT old_pay (idstud, idopt, plan, pay)                                    "
          " SELECT s.idstud, s.idopt, s.commoncountmoney/2, SUM(COALESCE(fact.moneypay, 0)) - s.commoncountmoney/2  "
          " FROM (                                                                                  "
          "      SELECT st.id as idstud, opts.id as idopt, opts.commoncountmoney                    "
          "      FROM students AS st, payoptstest as opts, voc as v                                 "
          "	     WHERE st.deleted = 0 AND opts.deleted = 0 AND v.deleted = 0                        "
          "      AND v.vkey = 'grp'  AND st.grpid = v.num AND opts.idgroup = st.grpid               "
          "      AND opts.datestart=@data_pre1 AND st.cityid != 0                                   "
          " ) as s                                                                                  "
          " LEFT JOIN payfactstest AS fact                                                          "
          " ON s.idopt = fact.idopts AND s.idstud = fact.idstud AND fact.deleted = 0                "
          " GROUP BY s.idstud, s.idopt");
    //# сделаеим для них проверку что бы не было отрицательных оплат
    mysql_query(mysql, "UPDATE old_pay SET old_pay.pay = 0 WHERE old_pay.pay < 0 ");

     //# это февральские последующие
    mysql_query(mysql,"INSERT old_pay (idstud, idopt, plan, pay)                                    "
          " SELECT s.idstud, s.idopt, s.commoncountmoney/2, SUM(COALESCE(fact.moneypay, 0))                  "
          " FROM (                                                                                  "
          "      SELECT st.id as idstud, opts.id as idopt, opts.commoncountmoney                    "
          "      FROM students AS st, payoptstest as opts, voc as v                                 "
          "	     WHERE st.deleted = 0 AND opts.deleted = 0 AND v.deleted = 0                        "
          "      AND v.vkey = 'grp'  AND st.grpid = v.num AND opts.idgroup = st.grpid               "
          "      AND opts.datestart=@data_pre3 AND st.cityid != 0                                   "
          " ) as s                                                                                  "
          " LEFT JOIN payfactstest AS fact                                                          "
          " ON s.idopt = fact.idopts AND s.idstud = fact.idstud AND fact.deleted = 0                "
          " GROUP BY s.idstud, s.idopt");
    //# сделаеим для них проверку что бы не было оплаты больше плана
    mysql_query(mysql,"UPDATE old_pay SET old_pay.pay = old_pay.plan WHERE old_pay.pay > old_pay.plan ");

    // этап 2
    // у стедента могут несколько категорий оплат за текущий период, то есть два сценария поведения
    // 1 если хотя бы по одной было заплачено(может быть несколько), то удалить те которые без оплаты
    // 2 если ни по одной не заплачено, то оставить только ту которая основная в группе

    // найдем студентов у которых проблемы
    mysql_query(mysql, "drop temporary table if exists bad_stud");
    mysql_query(mysql,
        " CREATE TEMPORARY TABLE bad_stud                  "
        " (                                                "
        "  id        int(11) NOT NULL AUTO_INCREMENT,      "
        "  idstud    int(11) NOT NULL,                     "
        "  _count    int(11) NOT NULL,                     "
        "  pay       int(11) NOT NULL,                     "
        "  INDEX (id),                                     "
        "  INDEX (idstud)                                  "
        " ) TYPE = HEAP ");
    mysql_query(mysql,"INSERT bad_stud (idstud, _count, pay) "
          " SELECT idstud, COUNT(0) as c, SUM(pay)           "
          " FROM old_pay                                     "
          " GROUP BY idstud "
          " HAVING c > 1");

    // найдем котагории которые являются для проблемных студентов основными
    mysql_query(mysql, "drop temporary table if exists main_opt");
    mysql_query(mysql,
        " CREATE TEMPORARY TABLE main_opt                  "
        " (                                                "
        "  id        int(11) NOT NULL AUTO_INCREMENT,      "
        "  grpid     int(11) NOT NULL,                     "
        "  idopt     int(11) NOT NULL,                     "
        "  count     int(11) NOT NULL,"
        "  INDEX (id),                                     "
        "  INDEX (grpid)                                   "
        " ) TYPE = HEAP ");
    mysql_query(mysql,"INSERT main_opt (grpid, idopt, count)  "
            " SELECT m.grpid, m.idopt, MAX(m.c)               "
            " FROM (SELECT s.grpid, pay.idopt, COUNT(*) as c  "
            "       FROM old_pay as pay, students as s        "
            "       WHERE pay.idstud = s.id AND pay.pay > 0   "
            "       GROUP BY s.grpid, pay.idopt               "
            "      ) as m                                     "
            " GROUP BY m.grpid");

    // сценарий 1
    mysql_query(mysql, " DELETE old_pay                          "
                       " FROM old_pay, bad_stud                  "
                       " WHERE old_pay.idstud = bad_stud.idstud  "
                       " AND bad_stud.pay > 0 AND old_pay.pay = 0");
    // сценарий 2
    mysql_query(mysql, " DELETE old_pay                                   "
                       " FROM old_pay, bad_stud, students as s, main_opt  "
                       " WHERE old_pay.idstud = bad_stud.idstud           "
                       " AND bad_stud.pay = 0 AND s.id = bad_stud.idstud  "
                       " AND main_opt.grpid = s.grpid                     "
                       " AND old_pay.idopt != main_opt.idopt");


    mysql_query(mysql, "drop temporary table if exists bad_stud");
    mysql_query(mysql, "drop temporary table if exists main_opt");
}