コード例 #1
0
ファイル: Form1.cs プロジェクト: joeytall/Terminator2.5
        private void populateGridWithMessageCount()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("MsgCount", typeof(int));
            dt.Columns.Add("File Name", typeof(string));
            int           fileColumnIndex = Grid.Columns["File Name"].Index;
            SqlConnection conn            = SystemMessage.InitSqlConnection();
            SqlCommand    command         = new SqlCommand();
            string        sql             = "";

            foreach (DataGridViewRow row in Grid.Rows)
            {
                string fileName         = row.Cells[fileColumnIndex].Value.ToString();
                string filePath         = txtPath.Text + "\\" + fileName;
                string fileNameWithPath = "";
                if (!fileName.Contains("\\"))
                {
                    fileNameWithPath = Regex.Split(txtPath.Text, @"\\").Last() + "/" + fileName;
                }

                fileNameWithPath = SystemMessage.ValidateFilename(fileNameWithPath);
                sql     = "SELECT COUNT(*) FROM systemmessage WHERE FILENAME = '" + fileNameWithPath + "'";
                command = new SqlCommand(sql, conn);
                string msgCount = command.ExecuteScalar().ToString();
                dt.Rows.Add(msgCount, fileName);
            }
            Grid.DataSource = dt;
            Grid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: joeytall/Terminator2.5
        private void CheckMessageExist()
        {
            int           fileColumnIndex = Grid.Columns["File Name"].Index;
            SqlConnection conn            = SystemMessage.InitSqlConnection();
            SqlCommand    command         = new SqlCommand();
            string        sql             = "";

            foreach (DataGridViewRow row in Grid.Rows)
            {
                string fileName = row.Cells[fileColumnIndex].Value.ToString();
                string filePath = txtPath.Text + "\\" + fileName;
                if (!fileName.Contains("\\"))
                {
                    fileName = Regex.Split(txtPath.Text, @"\\").Last() + "/" + fileName;
                }
                FileName = fileName.Replace("\\", "/");

                List <string> allLines     = File.ReadAllLines(filePath).ToList();
                List <string> linesWithMsg = allLines.Where(line => line.Contains("m_msg") && !line.Contains("//")).ToList();
                if (linesWithMsg.Count == 0)
                {
                    continue;
                }
                List <string> inFileMsgs = new List <string>();
                List <string> existMsgs  = new List <string>();
                foreach (string line in linesWithMsg)
                {
                    Regex           rx      = new Regex(@"T\d+");
                    MatchCollection matches = rx.Matches(line);
                    foreach (Match match in matches)
                    {
                        inFileMsgs.Add(match.ToString());
                    }
                }
                sql = "SELECT MsgId FROM systemmessage WHERE FILENAME = '" + FileName.Replace(".cs", "") + "'";
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                DataTable      dt = new DataTable();
                try
                {
                    da.Fill(dt);
                }
                catch
                {
                    dt = null;
                }
                da.Dispose();
                if (dt == null && inFileMsgs.Count != 0)
                {
                    console.AppendText(fileName + " has msg issues. \r\n");
                    console.AppendText(String.Join(", ", inFileMsgs).ToString() + " not found in database. \r\n");
                    console.ScrollToCaret();
                }

                foreach (DataRow dtrow in dt.Rows)
                {
                    existMsgs.Add(dtrow[0].ToString());
                }

                foreach (string msg in inFileMsgs)
                {
                    if (!existMsgs.Contains(msg))
                    {
                        console.AppendText(msg + " not found in database for file " + fileName + ". \r\n");
                        console.ScrollToCaret();
                    }
                }
            }
            console.AppendText("\r\nDone\r\n");
            console.ScrollToCaret();
            conn.Close();
        }