using Swift.DAL.VoucherReport;
using Swift.web.Library;
using System;
using System.Data;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;
namespace Swift.web.BillVoucher.DollarVoucherEntry
{
public partial class VoucherEntry : System.Web.UI.Page
{
private const string ViewFunctionId = "20150080";
private const string DateFunctionId = "20150040";
private readonly RemittanceLibrary _sdd = new RemittanceLibrary();
private readonly VoucherReportDAO _vrd = new VoucherReportDAO();
protected void Page_Load(object sender, EventArgs e)
{
Authenticate();
if (!IsPostBack)
{
AllowChangeDate();
Misc.MakeAmountTextBox(ref amt);
transactionDate.Text = DateTime.Today.ToString("yyyy-MM-dd");
//transactionDate.ReadOnly = true;
PopulateDDL();
}
divuploadMsg.Visible = false;
}
private void PopulateDDL()
{
_sdd.SetDDL(ref voucherType, "EXEC Proc_dropdown_remit @FLAG='voucherDDL'", "value", "functionName", "", "");
_sdd.SetDDL(ref FCY, "EXEC Proc_dropdown_remit @FLAG='Currency'", "val", "Name", "", "FCY");
_sdd.SetDDL(ref Department, "EXEC Proc_dropdown_remit @FLAG='Department'", "RowId", "DepartmentName", "", "Select Department");
_sdd.SetDDL(ref Branch, "EXEC Proc_dropdown_remit @FLAG='Branch'", "agentId", "agentName", "", "Select Branch");
}
private void Authenticate()
{
_sdd.CheckAuthentication(ViewFunctionId);
}
protected bool AllowChangeDate()
{
return _sdd.HasRight(DateFunctionId);
}
protected void addBtn_Click(object sender, EventArgs e)
{
if (GetStatic.ParseDouble(amt.Text) <= 0)
{
GetStatic.AlertMessage(this, "Please enter valid Amount! ");
amt.Text = " ";
amt.Focus();
return;
}
var result = _vrd.InsertTempVoucherEntry(GetStatic.GetSessionId(), GetStatic.GetUser(), acInfo.Value, dropDownDrCr.Text, amt.Text, Department.Text, Branch.Text
, EmpName.Text, Field1.Text, "", FCY.Text, FCYAmt.Text, Rate.Text, "", "");
if (result.ErrorCode == "1")
{
GetStatic.AlertMessage(this, result.Msg);
}
else
{
ShowTempVoucher();
}
}
private void ShowTempVoucher()
{
//show data on div
int sno = 0, drCount = 0, crCount = 0;
double drTotal = 0, crTotal = 0;
var dt = _vrd.GetTempVoucherEntryData(GetStatic.GetSessionId());
var sb = new StringBuilder("");
sb.AppendLine("
");
sb.AppendLine("
");
sb.AppendLine("");
sb.AppendLine("S. No | ");
sb.AppendLine("AC information | ");
sb.AppendLine("Voucher Date | ");
sb.AppendLine("FCY | ");
sb.AppendLine("FCY Amount | ");
sb.AppendLine("Rate | ");
sb.AppendLine("JPY Amount | ");
sb.AppendLine("Department | ");
sb.AppendLine("Branch | ");
sb.AppendLine("EmployeeName | ");
sb.AppendLine("Type | ");
sb.AppendLine("Select | ");
sb.AppendLine("
");
if (dt == null || dt.Rows.Count == 0)
{
sb.AppendLine("No transaction found! |
");
rpt_tempVoucherTrans.InnerHtml = sb.ToString();
return;
}
foreach (DataRow item in dt.Rows)
{
sno++;
if (item["part_tran_type"].ToString().ToLower() == "dr")
{
drCount++;
drTotal = drTotal + Convert.ToDouble(item["tran_amt"]);
}
else if (item["part_tran_type"].ToString().ToLower() == "cr")
{
crCount++;
crTotal = crTotal + Convert.ToDouble(item["tran_amt"]);
}
sb.AppendLine("");
sb.AppendLine("" + sno.ToString() + " | ");
sb.AppendLine(" " + item["acct_num"].ToString() + " | ");
sb.AppendLine(" " + item["tran_date"].ToString() + " | ");
sb.AppendLine(" " + item["trn_currency"].ToString() + " | ");
sb.AppendLine(" " + item["usd_amt"].ToString() + " | ");
sb.AppendLine(" " + item["ex_rate"].ToString() + " | ");
sb.AppendLine(" " + GetStatic.ShowDecimal(item["tran_amt"].ToString()) + " | ");
sb.AppendLine(" " + item["DepartmentName"].ToString() + " | ");
sb.AppendLine(" " + item["agentName"].ToString() + " | ");
sb.AppendLine(" " + item["emp_name"].ToString() + " | ");
sb.AppendLine("" + item["part_tran_type"].ToString() + " | ");
sb.AppendLine(" | ");
sb.AppendLine("
");
}
sb.AppendLine("");
sb.AppendLine(" Total Dr (" + drCount.ToString() + "): " + GetStatic.ShowDecimal(drTotal.ToString()) + " | ");
sb.AppendLine("
");
sb.AppendLine("");
sb.AppendLine(" Total Cr (" + crCount.ToString() + "): " + GetStatic.ShowDecimal(crTotal.ToString()) + " | ");
sb.AppendLine("
");
sb.AppendLine("");
sb.AppendLine("");
rpt_tempVoucherTrans.InnerHtml = sb.ToString();
}
protected void btnDelete_Click(object sender, EventArgs e)
{
var res = _vrd.DeleteRecordVoucherEntry(hdnRowId.Value);
if (res.ErrorCode == "0")
{
GetStatic.AlertMessage(this, res.Msg);
}
ShowTempVoucher();
}
protected void btnUnSave_Click(object sender, EventArgs e)
{
ShowTempVoucher();
}
protected void btnSave_Click(object sender, EventArgs e)
{
string voucherPath = "";
if (VImage.HasFile)
{
// Get the file extension
string fileExtension = System.IO.Path.GetExtension(VImage.FileName);
if (!IsImage(VImage))
{
msg.Visible = true;
mes.InnerHtml = "File types other than image are not acceptable.";
return;
}
else
{
// Get the file size
int fileSize = VImage.PostedFile.ContentLength;
// If file size is greater than 2 MB
if (fileSize > Convert.ToInt32(GetStatic.GetUploadFileSize()))
{
msg.Visible = true;
mes.InnerHtml = "File size cannot be greater than 2 MB";
return;
}
else
{
// Upload the file
voucherPath = "UploadedVoucher-" + GetTimestamp(DateTime.Now) + fileExtension;
string path = GetStatic.ReadWebConfig("filePath") + "VoucherDoc\\";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var filePath = path + voucherPath;
VImage.SaveAs(filePath);
}
}
}
string date = transactionDate.Text;
var res = _vrd.SaveTempTransactionUSD(GetStatic.GetSessionId(), date, narrationField.Text, chequeNo.Text, "J", GetStatic.GetUser(), voucherPath);
if (res.ErrorCode == "0")
{
chequeNo.Text = "";
narrationField.Text = "";
rpt_tempVoucherTrans.InnerHtml = res.Msg;
}
else
{
GetStatic.AlertMessage(this, res.Msg);
}
}
public static bool IsImage(FileUpload fileUpload)
{
if (Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".jpg"
&& Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".png"
&& Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".gif"
&& Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".jpeg")
{
return false;
}
if (fileUpload.PostedFile.ContentType.ToLower() != "image/jpg" &&
fileUpload.PostedFile.ContentType.ToLower() != "image/jpeg" &&
fileUpload.PostedFile.ContentType.ToLower() != "image/pjpeg" &&
fileUpload.PostedFile.ContentType.ToLower() != "image/gif" &&
fileUpload.PostedFile.ContentType.ToLower() != "image/x-png" &&
fileUpload.PostedFile.ContentType.ToLower() != "image/png")
{
return false;
}
try
{
byte[] buffer = new byte[512];
fileUpload.PostedFile.InputStream.Read(buffer, 0, 512);
string content = Encoding.UTF8.GetString(buffer);
if (Regex.IsMatch(content, @"