Пример #1
0
        private EDCLog parseEDCLog(string log)
        {
            EDCLog edc_log = new EDCLog();

            string[] token = log.Split('\t');
            // 20140908, TODO: Comment for SEQ of EDCLog
            //List<string> time_token = new List<string>(token[4].Split(':'));
            edc_log.type       = token[0];
            edc_log.edc_no     = token[1];
            edc_log.project_no = token[2];
            edc_log.emp_no     = token[3];
            edc_log.log_time   = token[4];

            /* 20140908, Comment for SEQ of EDCLog
             * edc_log.log_time_ms = time_token[time_token.Count - 1];
             * time_token.RemoveAt(time_token.Count - 1);
             * edc_log.log_time_YmdHMS = string.Join(":", time_token);
             */
            edc_log.content = (token.Length > 5) ? token[5] : "";
            return(edc_log);
        }
Пример #2
0
 private EDCLog parseEDCLog(string log)
 {
     EDCLog edc_log = new EDCLog();
     string[] token = log.Split('\t');
     // 20140908, TODO: Comment for SEQ of EDCLog
     //List<string> time_token = new List<string>(token[4].Split(':'));
     edc_log.type = token[0];
     edc_log.edc_no = token[1];
     edc_log.project_no = token[2];
     edc_log.emp_no = token[3];
     edc_log.log_time = token[4];
     /* 20140908, Comment for SEQ of EDCLog
     edc_log.log_time_ms = time_token[time_token.Count - 1];
     time_token.RemoveAt(time_token.Count - 1);
     edc_log.log_time_YmdHMS = string.Join(":", time_token);
     */
     edc_log.content = (token.Length > 5) ? token[5] : "";
     return edc_log;
 }
Пример #3
0
        private void syncEDCLog(string recv, NetworkStream clientStream)
        {
            string[] recv_list;
            recv_list = recv.Split('\n');
            ASCIIEncoding encoder = new ASCIIEncoding();
            string        send_str;

            byte[]  send_buf;
            DataSet edc_archive = new DataSet();

            using (SqlConnection sql_conn = new SqlConnection(this.sqlConnStr))
            {
                sql_conn.Open();
                //Start from 2nd line
                for (int i = 1; i < recv_list.Length; i++)
                {
                    string curr_log = recv_list[i].Trim();
                    if (curr_log.Length != 0)
                    {
                        EDCLog edc_log = parseEDCLog(curr_log);
                        //TODO, please note here should change to EDCLogArchive
                        using (SqlCommand sql_insert_log = new SqlCommand("INSERT INTO [dbo].[EDCLogTmp] (EDCLog) VALUES (@edc_log)", sql_conn))
                        {
                            sql_insert_log.CommandTimeout = 0;
                            sql_insert_log.Parameters.Add(kFieldEDCLog, SqlDbType.NVarChar);
                            sql_insert_log.Parameters[kFieldEDCLog].Value = curr_log;
                            sql_insert_log.CommandType = System.Data.CommandType.Text;
                            if (sql_insert_log.ExecuteNonQuery() != 1)
                            {
                                logger.ErrorText("Insert EDCLOG to EDCLogTmp failure");
                            }
                            else
                            {
                                logger.InfoText("Client thread insert EDC_log: " + curr_log);
                            }
                        }

                        if (edc_log.type == "CARD")
                        {
                            string[] content_token = edc_log.content.Split(' ');
                            if (content_token[0] == "VALID")
                            {
                                //TODO Exception here!!!其他資訊: 索引在陣列的界限之外。
                                //getdate()改用edc_log.log_time寫入EDC的時間
                                string sql_insert_pq = string.Format("INSERT INTO [dbo].[PQCardInfo] (EDCNO, CardNumber, UserNumber, ProjectNO, CardDT)" +
                                                                     "VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')", edc_log.edc_no, content_token[1], edc_log.emp_no, edc_log.project_no, edc_log.log_time);
                                using (SqlCommand cmd_Insert_pq = new SqlCommand(sql_insert_pq, sql_conn))
                                {
                                    cmd_Insert_pq.CommandType = System.Data.CommandType.Text;
                                    if (cmd_Insert_pq.ExecuteNonQuery() != 1)
                                    {
                                        logger.ErrorText(string.Format("Insert PQCardInfo to DB error: sql: {0}", sql_insert_pq));
                                    }
                                    else
                                    {
                                        logger.DebugText(string.Format("Insert PQCardInfo to DB success, sql: {0}", sql_insert_pq));
                                    }
                                }
                            }
                        }
                        else if (edc_log.type == "PRINT" || edc_log.type == "COPY")
                        {
                            List <KeyValuePair <string, int> > paper_usage = parseCountContent(edc_log.content);
                            foreach (KeyValuePair <string, int> usage in paper_usage)
                            {
                                string sql_insert_cc = string.Format("INSERT INTO [dbo].[CopyCount] (EDCNO, ProjectNO, UserNumber, PrintType, PrintCount, UseDT)" +
                                                                     "VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')",
                                                                     edc_log.edc_no, edc_log.project_no, edc_log.emp_no, usage.Key, usage.Value, edc_log.log_time);
                                using (SqlCommand cmd_insert_cc = new SqlCommand(sql_insert_cc, sql_conn))
                                {
                                    cmd_insert_cc.CommandType = System.Data.CommandType.Text;
                                    if (cmd_insert_cc.ExecuteNonQuery() != 1)
                                    {
                                        logger.ErrorText(string.Format("Insert CopyCount to DB error: sql: {0}", sql_insert_cc));
                                    }
                                    else
                                    {
                                        logger.DebugText(string.Format("Insert CopyCount to DB success: sql: {0}", sql_insert_cc));
                                    }
                                }
                            }
                        }
                        else if (edc_log.type == "SCAN")
                        {
                            string sql_scan = string.Format("INSERT INTO [dbo].[SEFScanInfo] (EDCNO, UserNumber, ProjectNo, ScanDT)" +
                                                            "VALUES ( '{0}', '{1}', '{2}', '{3}')", edc_log.edc_no, edc_log.emp_no, edc_log.project_no, edc_log.log_time);
                            using (SqlCommand cmd_scan = new SqlCommand(sql_scan, sql_conn))
                            {
                                cmd_scan.CommandType = System.Data.CommandType.Text;
                                if (cmd_scan.ExecuteNonQuery() != 1)
                                {
                                    logger.ErrorText(string.Format("Insert SEFScanInfo to DB error: sql: {0}", sql_scan));
                                }
                                else
                                {
                                    logger.DebugText(string.Format("Insert CopyCount to DB success: sql: {0}", sql_scan));
                                }
                            }
                        }

                        /* 20140908, TODO: Comment for SEQ of EDCLog
                         * //Send sync OK to client, EDCClient will drop log until this SYNC_LOG_OK
                         * send_str = kSyncLogOKCmd;
                         * send_str = send_str.Length.ToString() + "|" + send_str;
                         * send_buf = encoder.GetBytes(send_str);
                         * clientStream.Write(send_buf, 0, send_buf.Length);
                         * clientStream.Flush();
                         */
                    }
                }
            }
            //return true;
        }