Files
BealeEngineering/BealeEngineering/BealeEngineering.Accounts/Form1.cs
Bobbie Hodgetts 7210812458 Sales invoice 'Status'
Added 'status' to sales invoice
2020-02-05 21:18:39 +00:00

181 lines
6.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using BealeEngineering.Core.Data;
namespace BealeEngineering.Accounts
{
public partial class Form1 : Form
{
private string sqlConnectionString;
public Form1()
{
InitializeComponent();
sqlConnectionString = ConfigurationManager.ConnectionStrings["BealeEngSQLDb"].ToString();
}
public List<string> TableData { get; set; }
private void Form1_Load(object sender, EventArgs e)
{
UpdateTable();
button2_Click(null, null);
}
private void button1_Click(object sender, EventArgs e)
{
UpdateTable();
}
private void UpdateTable()
{
var readData = new Core.Data.Database.Client.ReadPurchaseOrderAllocation(sqlConnectionString);
var data = readData.Read();
//dataGridView1.Rows.AddRange()
purchaseOrderAllocationBindingSource.DataSource = data;
//dataGridView1.DataSource = data;
// high light over invoiced lines
for (var i = 0; i < dataGridView1.Rows.Count; i++)
{
decimal facility = (decimal)dataGridView1[9, i].Value;
if (facility == 0)
{
// code to grey out line
dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Gray;
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
else if (facility < 0)
{
// red line
dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
else
{
// default
dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
}
}
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
string poNumber = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
bool multiPoLine = false;
for (var i = 0; i < dataGridView1.Rows.Count; i++ )
{
if (i == e.RowIndex) { continue; }
else if (dataGridView1.Rows[i].Cells[6].Value.ToString() == poNumber)
{
multiPoLine = true;
break;
}
}
if (multiPoLine)
{
poNumber = poNumber + "-" + dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString().PadLeft(3, '0');
}
var dataIndexNo = dataGridView1.Rows[e.RowIndex].Index.ToString();
string cellValue = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
Clipboard.SetText(poNumber);
MessageBox.Show(poNumber);
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
var dataRead = new Core.Data.Database.Client.ReadSaleInvoiceAllocation(sqlConnectionString);
txtUnallocatedCount.Text = dataRead.GetUnallocatedInvoiceCount().ToString();
}
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
{
}
private void splitContainer3_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void testItToolStripMenuItem_Click(object sender, EventArgs e)
{
var inst = new Core.Test.Autoexec(sqlConnectionString);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void txtUnallocatedCount_TextChanged(object sender, EventArgs e)
{
}
private void xeroInvoiceToolStripMenuItem_Click(object sender, EventArgs e)
{
string fileInputPath =
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
+ @"\Dropbox\Beale Engineering Services Ltd\BE Accounts\Xero-Export-Invoices.csv";
string dialogText = "Importing file from location: " + Environment.NewLine + Environment.NewLine + fileInputPath;
DialogResult dialogResult = MessageBox.Show(dialogText, "Import Xero Invoice flat-file", MessageBoxButtons.OKCancel);
if (dialogResult == DialogResult.OK)
{
var importXeroInvoice = new BealeEngineering.Core.Logic.Import.XeroInvoiceFlatFile(sqlConnectionString);
importXeroInvoice.ByFilePath(fileInputPath);
dialogText = "Import complete." + Environment.NewLine + Environment.NewLine
+ importXeroInvoice.InvoicesProcessed + " invoice(s) found" + Environment.NewLine
+ importXeroInvoice.InvoicesCreated + " invoice(s) created" + Environment.NewLine
+ importXeroInvoice.InvoicesUpdated + " invoice(s) updated" + Environment.NewLine
+ importXeroInvoice.InvoicesSkipped + " invoice(s) skipped" + Environment.NewLine;
MessageBox.Show(dialogText);
}
}
private void xeroInvoiceToolStripMenuItem1_Click(object sender, EventArgs e)
{
string filePath =
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
+ @"\Dropbox\Beale Engineering Services Ltd\BE Accounts\Xero-Export-Invoices.csv";
string dialogText = "Exporting all sales invoices to location: " + Environment.NewLine + Environment.NewLine + filePath;
DialogResult dialogResult = MessageBox.Show(dialogText, "Export Xero Invoice flat-file", MessageBoxButtons.OKCancel);
if (dialogResult == DialogResult.OK)
{
var exportXeroInvoice = new BealeEngineering.Core.Logic.Export.XeroInvoiceFlatFile(sqlConnectionString);
exportXeroInvoice.FileOutputPath = filePath;
exportXeroInvoice.Execute();
dialogText = "Export complete." + Environment.NewLine + Environment.NewLine
+ exportXeroInvoice.InvoicesExported + " invoice(s) exported" + Environment.NewLine;
MessageBox.Show(dialogText);
}
}
}
}