示例#1
0
 private int openFile(List <string> str, string file)
 {
     //ファイルを開いて、strリストの中身を入れる
     try
     {
         Encoding enc = Encoding.GetEncoding("shift_jis");
         str.AddRange(File.ReadAllLines(file, enc));
     }
     catch (Exception ex)
     {
         //ファイルの読み込み時のエラー
         if (logPath == "")
         {
             string   path = Assembly.GetExecutingAssembly().Location;
             string   dflt = path + "\\default.log";
             ClassLog cl   = new ClassLog(path);
             cl.logError(file, ex);
             //cl.dispose();
         }
         else
         {
             ClassLog cl = new ClassLog(logPath);
             cl.logError(file, ex);
             //cl.dispose();
         }
         return(1);
     }
     return(0);
 }
示例#2
0
        private int readTXTFile(string txt, List <string> skt)
        {
            //写研データを読込んで、タグを区別する
            ClassLog cl = new ClassLog(logPath);

            cl.logInfo("写研データを(byte)読み込んで、タグを収集します。");
            FileStream fs = null;

            byte[] bs  = new byte[0x1000];
            bool   flg = false;
            string tmp = "";

            try
            {
                fs = new FileStream(txt, FileMode.Open, FileAccess.Read);
                while (fs.Read(bs, 0, bs.Length) > 0)
                {
                    foreach (byte b in bs)
                    {
                        if (b >= F0)
                        {
                            flg = true;
                            tmp = String.Format("{0:X}", b);
                        }
                        else if (flg)
                        {
                            flg  = false;
                            tmp += String.Format("{0:X}", b);
                            //同じ値が入らないようソート
                            if (!skt.Contains(tmp))
                            {
                                skt.Add(tmp);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                cl.logError(txt, ex);
                return(1);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
            skt.Remove("");
            return(0);
        }
示例#3
0
        private int writeTXTFile(string txt)
        {
            ClassLog cl = new ClassLog(logPath);

            cl.logInfo("タグファイルの書き込み開始:" + txt);

            StreamWriter  sw  = null;
            StringBuilder tmp = new StringBuilder();

            try
            {
                sw = new StreamWriter(txt, false, Encoding.GetEncoding("shift_jis"));
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    for (int j = 0; j < dataGridView1.ColumnCount; j++)
                    {
                        if (dataGridView1.Rows[i].Cells[j].Value != null)
                        {
                            tmp.Append(dataGridView1.Rows[i].Cells[j].Value.ToString());
                        }
                        tmp.Append(';');
                    }
                    sw.WriteLine(tmp.ToString().Substring(0, tmp.ToString().Length - 1));
                    tmp.Clear();
                }
            }
            catch (Exception ex)
            {
                cl.logError(txt + "の書き込み失敗:", ex);
                return(1);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                    sw.Dispose();
                    //cl.dispose();
                }
            }

            return(0);
        }
示例#4
0
        private void setDT(string str, DataTable dt)
        {
            ClassLog cl = new ClassLog(logPath);

            cl.logInfo("SKTファイルの読み込み開始");
            try
            {
                Encoding enc   = Encoding.GetEncoding("shift_jis");
                string[] lines = File.ReadAllLines(str, enc);

                dt.Columns.Add("pattern", typeof(int));
                dt.Columns.Add("SK", typeof(string));
                dt.Columns.Add("MCS", typeof(string));
                dt.Columns.Add("detail", typeof(string));

                for (int i = 0; i < lines.Length; i++)
                {
                    if (lines[i] != "")
                    {
                        string[] parts = lines[i].Split(';');
                        if (parts.Length == 4)
                        {
                            dt.Rows.Add(parts[0], parts[1], parts[2], parts[3]);
                        }
                        else
                        {
                            cl.logDebug(str + ":" + i + "行目フォーマットエラー:" + lines[i]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                cl.logError(str, ex);
                //cl.dispose();
            }
        }
示例#5
0
        private void openIni()
        {
            const string DATAFILENAME = "datafilename";
            const string LOGPATH      = "logpath";
            //ini設定を行う
            string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string iniFile = appPath + "\\setup.ini";

            //setup.iniファイルの存在確認
            if (File.Exists(iniFile))
            {
                //ファイルを開き、設定値を行う
                List <string> lines = new List <string>();
                if (openFile(lines, iniFile) == 0)
                {
                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    foreach (string line in lines)
                    {
                        if (line != "")
                        {
                            string[] tmp = line.Split('=');
                            if (tmp.Length == 2)
                            {
                                dict[tmp[0].Trim()] = tmp[1].Trim();
                            }
                        }
                    }
                    fileMdb = dict[DATAFILENAME];
                    logPath = dict[LOGPATH];
                    ClassLog cl1 = new ClassLog(logPath);
                    cl1.logInfo("Main開始");
                    //cl1.dispose();

                    lines.Clear();
                    return;
                }
            }
            //デフォルト値を設定し、Setup.iniファイルを作成する
            const string DT  = "skttable.mdb";
            const string LP  = "C:\\log";
            Encoding     enc = Encoding.GetEncoding("shift_jis");
            StreamWriter sw  = null;
            ClassLog     cl  = new ClassLog(LP);

            logPath = LP;
            try
            {
                cl.logInfo("Main開始/setup.ini作成");
                sw = new StreamWriter(iniFile, false, enc);
                sw.WriteLine(LOGPATH + '=' + LP);
                sw.WriteLine(DATAFILENAME + '=' + DT);
            }
            catch (Exception ex)
            {
                cl.logError(iniFile, ex);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
                //cl.dispose();
            }
        }
示例#6
0
        public int checkDB(string str, string log, DataTable dt)
        {
            ClassLog cl = new ClassLog(log);

            cl.logInfo("MSAccess接続します。");
            logPath = log;
            mdb     = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + str;
            //mdbファイルの存在確認
            if (!File.Exists(mdb))
            {
                //mdbファイルの作成
                cl.logInfo("mdbファイルが存在しません。作成します。");
                try
                {
                    File.Copy(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + tmpDB, mdb);
                }
                catch (Exception ex)
                {
                    cl.logError("tmpmdbファイル移動エラー", ex);
                }
                //cl.dispose();
                return(1);
            }
            else
            {
                //mdbファイルの中身、テーブルが格納されているか確認する
                cl.logInfo("テーブルの確認、開始");

                OleDbConnection con = new OleDbConnection();
                OleDbCommand    cmd = null;
                OleDbDataReader odr = null;
                con.ConnectionString = strOLEDB + strDS + mdb;
                try
                {
                    con.Open();
                    cmd             = new OleDbCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = sql1;
                    odr             = cmd.ExecuteReader();
                    if (odr != null)
                    {
                        cl.logInfo("データ読み込み開始");
                        dt.Load(odr);
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    cl.logError("テーブルが破壊されています。", ex);
                }
                finally
                {
                    if (con != null)
                    {
                        con.Close();
                        cmd.Dispose();
                        con.Dispose();
                    }
                }
                return(1);
            }
        }
示例#7
0
        private void setFile(string str)
        {
            ClassLog cl = new ClassLog(logPath);

            cl.logInfo("写研テキストファイルを開く:" + fileTXT);
            Encoding enc = Encoding.GetEncoding("shift_jis");
            //写研テキストファイルを開く
            List <string> lines = new List <string>();
            StreamReader  sr    = null;

            try
            {
                sr = new StreamReader(fileTXT, enc);
                while (sr.Peek() > -1)
                {
                    lines.Add(sr.ReadLine());
                }
            }
            catch (Exception ex)
            {
                cl.logError(fileTXT + "の読み込み失敗:", ex);
                return;
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                }
            }

            //変換処理
            lines.Remove("\n");
            replaceT(lines);
            //書き込み
            cl.logInfo("書き込み開始:" + str);
            StreamWriter sw = null;

            try
            {
                sw = new StreamWriter(str, false, Encoding.GetEncoding("shift_jis"));
                foreach (string line in lines)
                {
                    sw.WriteLine(line);
                }
            }
            catch (Exception ex)
            {
                cl.logError(str + "の書き込み失敗:", ex);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                    sw.Dispose();
                    //cl.dispose();
                    lines.Clear();
                }
            }
        }