You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
273 lines
13 KiB
273 lines
13 KiB
3 months ago
|
using BiskLog_Point_Of_Sale.Classes;
|
||
|
using BiskLog_Point_Of_Sale.Multiple_Login;
|
||
|
using BiskLog_Point_Of_Sale.OPS_Report.Products.Classes;
|
||
|
using BiskLog_Point_Of_Sale.Properties;
|
||
|
using ClosedXML.Excel;
|
||
|
using Microsoft.Reporting.WinForms;
|
||
|
using Point_Of_Sale_Managment;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel;
|
||
|
using System.Data;
|
||
|
using System.Data.SqlClient;
|
||
|
using System.Drawing;
|
||
|
using System.IO;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Windows.Forms;
|
||
|
|
||
|
namespace BiskLog_Point_Of_Sale.OPS_Report.Sales
|
||
|
{
|
||
|
public partial class RestockAdjustment : Form
|
||
|
{
|
||
|
SqlConnection cn;
|
||
|
SqlCommand cm;
|
||
|
SqlDataReader dr;
|
||
|
DatabaseConn conn = new DatabaseConn();
|
||
|
List<Inventory> restock = new List<Inventory>();
|
||
|
public RestockAdjustment()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
cn = new SqlConnection(conn.MyConnection());
|
||
|
headingPanel.Left = (ClientSize.Width - headingPanel.Width) / 2;
|
||
|
rangePanel.Left = (ClientSize.Width - rangePanel.Width) / 2;
|
||
|
groupBox1.Left = (ClientSize.Width - groupBox1.Width) / 2;
|
||
|
EpE.Left = (ClientSize.Width - EpE.Width) / 2;
|
||
|
EpE.Top = (ClientSize.Height - EpE.Height) / 2;
|
||
|
}
|
||
|
public int getrestocks()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
sellers.Invoke(new Action(() =>
|
||
|
{
|
||
|
int filter = 50;
|
||
|
if (!String.IsNullOrEmpty(textBox1.Text))
|
||
|
{
|
||
|
filter = int.Parse(textBox1.Text);
|
||
|
}
|
||
|
restock.Clear();
|
||
|
sellers.Rows.Clear();
|
||
|
head.Text = "Date : " + dateLower.Value.ToLongDateString() + " to " + dateHigher.Value.ToLongDateString();
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Select top(@filter) tbStock.sdate,p.product_name,tbStock.qty from tbStock Inner Join tblProduct p On p.pcode = tbStock.pcode " +
|
||
|
"where tbStock.branchID = @branchID and tbStock.sdate between (@lower) and (@higher)", cn);
|
||
|
cm.Parameters.AddWithValue("@lower", dateLower.Value.ToString("yyyy-MM-dd"));
|
||
|
cm.Parameters.AddWithValue("@higher", dateHigher.Value.ToString("yyyy-MM-dd"));
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.Parameters.AddWithValue("@filter", filter);
|
||
|
cm.ExecuteNonQuery();
|
||
|
dr = cm.ExecuteReader();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
Inventory inventory = new Inventory();
|
||
|
inventory.brand = Convert.ToDateTime(dr[0].ToString()).ToLongDateString();
|
||
|
inventory.productname = dr[1].ToString();
|
||
|
inventory.quantity = dr[2].ToString();
|
||
|
restock.Add(inventory);
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
cn.Close();
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
private int GenerateExcel(List<Inventory> publish, string filepath)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var workbook = new XLWorkbook();
|
||
|
var worksheet = workbook.Worksheets.Add(title.Text);
|
||
|
int i = 4;
|
||
|
worksheet.Cell("A1").Value = title.Text;
|
||
|
worksheet.Cell("A2").Value = head.Text;
|
||
|
worksheet.Cell("A3").Value = "DATE";
|
||
|
worksheet.Cell("B3").Value = "PRODUCT NAME";
|
||
|
worksheet.Cell("C3").Value = "QUANTITY";
|
||
|
|
||
|
worksheet.Range("A1:C1").Row(1).Merge();
|
||
|
worksheet.Range("A2:C2").Row(1).Merge();
|
||
|
|
||
|
worksheet.Range("A1:C1").Style.Fill.BackgroundColor = XLColor.FromArgb(10, 10, 56);
|
||
|
worksheet.Range("A2:C2").Style.Fill.BackgroundColor = XLColor.FromArgb(10, 10, 56);
|
||
|
worksheet.Range("A3:C3").Style.Fill.BackgroundColor = XLColor.FromArgb(10, 10, 56);
|
||
|
worksheet.Range("A1:C1").Style.Font.FontColor = XLColor.White;
|
||
|
worksheet.Range("A2:C2").Style.Font.FontColor = XLColor.White;
|
||
|
worksheet.Range("A3:C3").Style.Font.FontColor = XLColor.White;
|
||
|
foreach (Inventory row in publish)
|
||
|
{
|
||
|
|
||
|
worksheet.Cell("A" + i).Style.Border.SetLeftBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("C" + i).Style.Border.SetRightBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("A" + i).Value = row.brand;
|
||
|
worksheet.Cell("B" + i).Value = row.productname;
|
||
|
worksheet.Cell("C" + i).Value = row.quantity;
|
||
|
worksheet.Cell("A" + i).Style.Border.SetBottomBorder(XLBorderStyleValues.Thin);
|
||
|
worksheet.Cell("B" + i).Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin);
|
||
|
worksheet.Cell("C" + i).Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin);
|
||
|
i++;
|
||
|
}
|
||
|
worksheet.Cell("A1").Style.Border.SetLeftBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("C1").Style.Border.SetRightBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("A2").Style.Border.SetLeftBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("C2").Style.Border.SetRightBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("A3").Style.Border.SetLeftBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("C3").Style.Border.SetRightBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("A3").Style.Border.SetBottomBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("B3").Style.Border.SetBottomBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cell("C3").Style.Border.SetBottomBorder(XLBorderStyleValues.Thick);
|
||
|
worksheet.Cells().Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||
|
worksheet.Cells().Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||
|
worksheet.Row(1).Height = 20.0;
|
||
|
worksheet.Row(2).Height = 20.0;
|
||
|
worksheet.Columns().AdjustToContents();
|
||
|
worksheet.Column(1).Width = 30.43;
|
||
|
workbook.SaveAs(filepath);
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
private async void RestockAdjustment_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
Task<int> task = new Task<int>(getrestocks);
|
||
|
EpE.Visible = true;
|
||
|
holding.Value = 0;
|
||
|
task.Start();
|
||
|
var progress = new Progress<int>(percent =>
|
||
|
{
|
||
|
holding.Value = percent;
|
||
|
|
||
|
});
|
||
|
await Task.Run(() => Progression.DoSomething(progress));
|
||
|
int result = await task;
|
||
|
if (result == 1)
|
||
|
{
|
||
|
foreach (Inventory varseller in restock)
|
||
|
{
|
||
|
sellers.Rows.Add(varseller.brand, varseller.productname, varseller.quantity);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string title = "Error Occurred";
|
||
|
string message = "An error occurred while trying to generate report, please try again later";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
EpE.Visible = false;
|
||
|
}
|
||
|
|
||
|
private async void Button2_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if (restock.Count > 0)
|
||
|
{
|
||
|
string filelocation = "";
|
||
|
DialogResult result = excelExport.ShowDialog();
|
||
|
if (result == DialogResult.OK)
|
||
|
{
|
||
|
filelocation = excelExport.FileName;
|
||
|
Task<int> task = new Task<int>(() => GenerateExcel(restock, filelocation));
|
||
|
EpE.Visible = true;
|
||
|
holding.Value = 0;
|
||
|
task.Start();
|
||
|
var progress = new Progress<int>(percent =>
|
||
|
{
|
||
|
holding.Value = percent;
|
||
|
|
||
|
});
|
||
|
await Task.Run(() => Progression.DoSomething(progress));
|
||
|
int report = await task;
|
||
|
if (report == 1)
|
||
|
{
|
||
|
string title = "Success";
|
||
|
string message = "Excel report exported successfully";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string title = "Error Occurred";
|
||
|
string message = "An error occurred while exporting the excel report, please try again later.";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
EpE.Visible = false;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string title = "Report Not available";
|
||
|
string message = "Sorry there was no report generated to complete this action, please try again later.";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void Button1_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if (restock.Count > 0)
|
||
|
{
|
||
|
string printerReportDefault = Settings.Default.ReportPrinter;
|
||
|
string printLocation;
|
||
|
ProductHeaders headers = new ProductHeaders();
|
||
|
headers.header1 = title.Text;
|
||
|
headers.header2 = head.Text;
|
||
|
List<ProductHeaders> reportHeaders = new List<ProductHeaders>();
|
||
|
reportHeaders.Add(headers);
|
||
|
if (printerReportDefault == "Microsoft XPS Document Writer" || printerReportDefault == "Microsoft Print to PDF")
|
||
|
{
|
||
|
FolderBrowserDialog folder = new FolderBrowserDialog();
|
||
|
DialogResult result = folder.ShowDialog();
|
||
|
if (result == DialogResult.OK && !String.IsNullOrEmpty(folder.SelectedPath))
|
||
|
{
|
||
|
printLocation = folder.SelectedPath +@"\"+ title.Text + @"report" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".pdf";
|
||
|
LocalReport report = new LocalReport();
|
||
|
string path = Path.GetDirectoryName(Application.ExecutablePath);
|
||
|
string fullpath = Path.GetDirectoryName(Application.ExecutablePath).Remove(path.Length - 10) +
|
||
|
@"\OPS Report\Products\Reports\Restock.rdlc";
|
||
|
report.ReportPath = fullpath;
|
||
|
report.DataSources.Add(new ReportDataSource("Restock", restock));
|
||
|
report.DataSources.Add(new ReportDataSource("Header", reportHeaders));
|
||
|
ReportConfig.PrintToPrinter(report, printLocation, printerReportDefault);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printLocation = "";
|
||
|
LocalReport report = new LocalReport();
|
||
|
string path = Path.GetDirectoryName(Application.ExecutablePath);
|
||
|
string fullpath = Path.GetDirectoryName(Application.ExecutablePath).Remove(path.Length - 10) +
|
||
|
@"\OPS Report\Products\Reports\Restock.rdlc";
|
||
|
report.ReportPath = fullpath;
|
||
|
report.DataSources.Add(new ReportDataSource("Restock", restock));
|
||
|
report.DataSources.Add(new ReportDataSource("Header", reportHeaders));
|
||
|
ReportConfig.PrintToPrinter(report, printLocation, printerReportDefault);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string title = "Report Not available";
|
||
|
string message = "Sorry there was no report generated to complete this action, please try again later.";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|