using Swift.DAL.VoucherReport;
using Swift.web.Library;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Swift.web.BillVoucher.DollarVoucher
{
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)
{
_sdd.CheckSession();
if (!IsPostBack)
{
Authenticate();
AllowChangeDate();
transactionDate.Text = DateTime.Today.ToString("d");
transactionDate.Attributes.Add("readonly", "readonly");
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(FCYAmt.Text) <= 0)
{
GetStatic.AlertMessage(this, "Please enter valid Amount! ");
FCYAmt.Focus();
return;
}
var result = _vrd.InsertDollarTransferCharge(GetStatic.GetSessionId(), GetStatic.GetUser(), acInfo.Value, dropDownDrCr.Text,Department.Text, Branch.Text
, EmpName.Text, Field1.Text,FCY.Text, FCYAmt.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.GetTempTransferChargeData(GetStatic.GetSessionId());
var sb = new StringBuilder("");
sb.AppendLine("
");
sb.AppendLine("
");
sb.AppendLine("");
sb.AppendLine("S. No | ");
sb.AppendLine("AC information | ");
sb.AppendLine("FCY | ");
sb.AppendLine("FCY Amount | ");
sb.AppendLine("Rate | ");
sb.AppendLine("Department | ");
sb.AppendLine("Branch | ");
sb.AppendLine("EmployeeName | ");
sb.AppendLine("Type | ");
sb.AppendLine("KRW Amount | ");
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["trn_currency"].ToString() + " | ");
sb.AppendLine(" " + item["usd_amt"].ToString() + " | ");
sb.AppendLine(" " + item["ex_rate"].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(" " + GetStatic.ShowDecimal(item["tran_amt"].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 = "/VerificationDoc/" + "UploadedVoucher-" + GetTimestamp(DateTime.Now) + fileExtension;
var filePath = GetStatic.ReadWebConfig("filePath") + voucherPath;
VImage.SaveAs(filePath);
}
}
}
string date = transactionDate.Text;
var res = _vrd.SaveTransferCharge(GetStatic.GetSessionId(), date, narrationField.Text,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, @"