private void btnConvert_Click(object sender, EventArgs e) { string logFilePath = System.Configuration.ConfigurationSettings.AppSettings["LOG_FILE_PATH"]; OTLog log = new OTLog(logFilePath); CheckFile(); // Get folder name in app.config file string fnOut = OTConverterMerchant.DoConvertFile(txtElectraFolder.Text, log); log.Close(); if (fnOut.Length > 0) { txtFCCFolder.Text = fnOut; //Dat sua ngay 14/01/2012 --> co phi thi thong bao len string msg = ""; if (phi_flag != "") { msg = "Convert successfully. Có phí chiết khấu."; } else msg = "Convert successfully. Không có phí."; if (daily_khongPhi != "") msg += "\n \nĐại lý chưa thu phí: " + daily_khongPhi; MessageBox.Show(msg); OTConverterMerchant.ImportFee_Flag = ""; //End Dat sua ngay 14/01/2012 --> co phi thi thong bao len Process.Start(fnOut); } else { txtFCCFolder.Text = "Convert fail."; MessageBox.Show("Convert fail. Please see the log file"); Process.Start(log.LogFile); } phi_flag = ""; OTConverterMerchant.msg_show = 0; daily_khongPhi = ""; //Process.Start(iflexFolder); }
/// <summary> /// Convert 1 files in Opus format to Oracle format /// </summary> /// <param name="fnInput"></param> /// <param name="fnOutput"></param> /// <returns></returns> public static string DoConvertFile(string fnInput, OTLog log) { try { // prepare folder string folderInp = System.Configuration.ConfigurationSettings.AppSettings["INPUT_FOLDER"]; string folderOut = System.Configuration.ConfigurationSettings.AppSettings["OUTPUT_FOLDER"]; string bakFolder = folderInp + @"\BAK\ELT_MER_" + DateTime.Now.ToString("dd_MM_yyyy"); if (!Directory.Exists(bakFolder)) { Directory.CreateDirectory(bakFolder); } folderOut = folderOut + @"\IFLEX_MER_" + DateTime.Now.ToString("dd_MM_yyyy"); folderOut = @"D:\Temp\Oracle\IFLEX_MER_" + DateTime.Now.ToString("dd_MM_yyyy"); if (!Directory.Exists(folderOut)) { Directory.CreateDirectory(folderOut); } // prepare file name // Get file name only string fn = fnInput.Substring(fnInput.LastIndexOf('\\') + 1); string name = fn.Substring(0, fn.IndexOf('.')); string fnOut = folderOut + @"\" + name + ".TXT"; // Do convert TextReader input = new StreamReader(fnInput); TextWriter output = new StreamWriter(fnOut); string str = ""; // Ignore the header line str = input.ReadLine(); int index = 0; //output.WriteLine(str); while (true) { str = input.ReadLine(); if (str.Substring(0, 3).CompareTo("EOF") == 0) { break; } // write line with the second line and above //if (index > 0) //{ // output.WriteLine(); //} string strOut = OTConverterMerchant.DoConvertRow(str); if (strOut != "") { output.WriteLine(strOut); // index++; } // TODO: comment for testing //strOut = OTConverter.GenerateIncomeRow(str); //output.WriteLine(strOut); //strOut = OTConverter.GenerateTaxRow(str); //output.Write(strOut); // TODO: comment for testing //index++; } //output.Write(str); input.Close(); output.Close(); // In case successful : Move fnInp to BACKUP folder string bakfn = bakFolder + @"\" + fn; if (File.Exists(bakfn)) { File.Delete(bakfn); } File.Copy(fnInput, bakfn, true); log.WriteLine("Converting " + fn + " SUCCESSFULLY"); return fnOut; } catch (Exception ex) { log.WriteLine(ex.Message + ".\nSTACK TRACE:" + ex.StackTrace); return ""; } return ""; }