public string BuildBatchfile(string BatchCode, string BillCode, int trans, double total) { int new_trans = trans + 1; DateTime now = DateTime.Now; string strdt = now.ToString("dMMyy"); string name = "C" + BillCode + "" + strdt; string filename = name + ".txt"; int GroupCode = 6; int ValueCode = 2; string reportFolder = datafile.GetSystemParameter(GroupCode, ValueCode); if (reportFolder.Equals("")) { reportFolder = "C:\\Interface\\BatchFiles\\"; } CheckPath(reportFolder); TextWriter tw = new StreamWriter(reportFolder + filename); try { tw.WriteLine("000CSU" + DateTime.Now.ToString("yyyyMMdd") + "000000" + BillCode.PadLeft(3, ' ') + "1".PadLeft(4, ' ') + "" + new_trans.ToString().PadLeft(6, ' ') + "" + total.ToString().PadLeft(12, ' '));//File Header /// Details DataTable dtpayments = datafile.GetTransByBatch(BatchCode); string[] batchArray = BatchCode.Split('-'); string batchno = batchArray[1].ToString(); foreach (DataRow dr in dtpayments.Rows) { string RecieptNo = dr["Receiptno"].ToString(); string ChequeNo = ""; string custaccount = dr["CustomerRef"].ToString(); DateTime payDate = DateTime.Parse(dr["PayDate"].ToString()); string payDateStr = payDate.ToString("yyyyMMdd"); DateTime postDate = DateTime.Parse(dr["PostDate"].ToString()); string postDateStr = payDate.ToString("yyyyMMdd"); double amount = double.Parse(dr["TranAmount"].ToString()); //string PaymentTypeCode = dr["PaymentType"].ToString(); string PaymentTypeCode = "2"; string line = batchno.PadLeft(8, ' ') + "" + RecieptNo.PadLeft(10, '0') + "" + BillCode + "" + custaccount.PadLeft(10, ' ') + " " + PaymentTypeCode + "N" + ChequeNo.PadLeft(16, ' ') + "" + payDateStr + "" + postDateStr + "" + amount.ToString().PadLeft(12, ' ') + "" + "".PadLeft(4, ' '); tw.WriteLine(line); } } catch (Exception ex) { throw ex; } finally { tw.Close(); } string fullPath = reportFolder + "\\" + filename; return(fullPath); }