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.
334 lines
14 KiB
334 lines
14 KiB
using BiskLog_Point_Of_Sale.Classes;
|
|
using BiskLog_Point_Of_Sale.Multiple_Login;
|
|
using BiskLog_Point_Of_Sale.Properties;
|
|
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.Net.Mail;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace BiskLog_Point_Of_Sale.Delivery
|
|
{
|
|
public partial class DeliveryDetails : Form
|
|
{
|
|
SqlConnection cn;
|
|
SqlCommand cm;
|
|
SqlDataReader dr;
|
|
DatabaseConn conn = new DatabaseConn();
|
|
public static List<OrderInvoice> deliveryInvoice = new List<OrderInvoice>();
|
|
public static List<products> productsList = new List<products>();
|
|
string deliveryID;
|
|
public bool delivered = false, cancelled = false;
|
|
public DeliveryDetails(string orderID = null, string status = null)
|
|
{
|
|
InitializeComponent();
|
|
cn = new SqlConnection(conn.MyConnection());
|
|
deliveryID = orderID;
|
|
if (status == "DELIVERED")
|
|
{
|
|
panel3.Visible = false;
|
|
lblStatus.Text = status;
|
|
lblStatus.ForeColor = Color.FromName("DarkGreen");
|
|
button2.Visible = false;
|
|
button3.Visible = false;
|
|
}
|
|
else if (status == "CANCELLED")
|
|
{
|
|
panel3.Visible = false;
|
|
lblStatus.Text = status;
|
|
lblStatus.ForeColor = Color.FromName("Crimson");
|
|
button2.Visible = false;
|
|
button3.Visible = false;
|
|
}
|
|
else if (status == "ASSIGNED TO TRUCK")
|
|
{
|
|
lblStatus.Text = status;
|
|
lblStatus.ForeColor = Color.FromName("RoyalBlue");
|
|
button2.Visible = true;
|
|
button3.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
lblStatus.Text = status;
|
|
lblStatus.ForeColor = Color.FromName("RoyalBlue");
|
|
button2.Visible = false;
|
|
button3.Visible = true;
|
|
}
|
|
}
|
|
|
|
private void Exit_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void Exit_MouseEnter(object sender, EventArgs e)
|
|
{
|
|
exit.BackColor = Color.Crimson;
|
|
}
|
|
|
|
private void Exit_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
exit.BackColor = Color.FromArgb(20, 158, 137);
|
|
}
|
|
|
|
private async void NewDelivery_Load(object sender, EventArgs e)
|
|
{
|
|
Task<int> task = new Task<int>(loadDetails);
|
|
holding.Visible = true;
|
|
task.Start();
|
|
int result = await task;
|
|
if (result != 1)
|
|
{
|
|
string title = "AN ERROR OCCURRED";
|
|
string message = "An error occurred while loading order details, please try again later";
|
|
NoAction noAction = new NoAction(title, message);
|
|
noAction.BringToFront();
|
|
noAction.ShowDialog();
|
|
}
|
|
holding.Visible = false;
|
|
}
|
|
|
|
bool IsValidEmail(string email)
|
|
{
|
|
try
|
|
{
|
|
var addr = new MailAddress(email);
|
|
return addr.Address == email;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
private async void Button1_Click(object sender, EventArgs e)
|
|
{
|
|
if (!String.IsNullOrEmpty(lblEmail.Text))
|
|
{
|
|
if (IsValidEmail(lblEmail.Text))
|
|
{
|
|
holding.Visible = true;
|
|
Task<int> taskO = new Task<int>(updateEmail);
|
|
taskO.Start();
|
|
int youin = await taskO;
|
|
if (youin == 1)
|
|
{
|
|
string titled = "Update Successfully";
|
|
string messaged = "Recipient's details updated successfully";
|
|
NoAction noActiond = new NoAction(titled, messaged);
|
|
noActiond.BringToFront();
|
|
noActiond.ShowDialog();
|
|
}
|
|
else
|
|
{
|
|
string titles = "Update failed";
|
|
string messages = "An error occurred while trying to update customer's details";
|
|
NoAction noActions = new NoAction(titles, messages);
|
|
noActions.BringToFront();
|
|
noActions.ShowDialog();
|
|
}
|
|
holding.Visible = false;
|
|
}
|
|
}
|
|
}
|
|
public int loadDetails()
|
|
{
|
|
try
|
|
{
|
|
int i = 1;
|
|
cn.Open();
|
|
invoiceDetails.Invoke(new Action(() =>
|
|
{
|
|
invoiceDetails.Rows.Clear();
|
|
cm = new SqlCommand("Declare @totalProduct decimal(19,2) = (Select Sum(cost) from tblDeliveryDetails where deliveryID = @deliveryID) " +
|
|
"Declare @Addition decimal(19, 2) = case when(Select totalCost from tblDeliveryHead where deliveryID = @deliveryID) - @totalProduct <= 0 then 0 " +
|
|
"else (Select totalCost from tblDeliveryHead where deliveryID = @deliveryID) - @totalProduct end " +
|
|
"Select DR.fullname,DR.address,DR.telephone,DR.email,DR.fromDate,DR.toDate,DH.totalCost,DP.product_name,DD.quantity,DD.cost,@totalProduct,@Addition,DD.pcode,u.unitname,DD.unit from " +
|
|
"tblDeliveryDetails DD Inner Join tblDeliveryRecipients DR on DR.deliveryID = DD.deliveryID Inner Join tblDeliveryHead DH On DH.deliveryID = DD.deliveryID Inner Join " +
|
|
"tblProduct DP On DP.pcode = DD.pcode Inner Join UnitOfMeasure u On u.unitCode = DD.unit where DD.deliveryID = @deliveryID and DH.branchID = @branchID", cn);
|
|
cm.Parameters.AddWithValue("@deliveryID", deliveryID);
|
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
|
cm.ExecuteNonQuery();
|
|
dr = cm.ExecuteReader();
|
|
while (dr.Read())
|
|
{
|
|
lblFullname.Text = dr[0].ToString().ToUpper();
|
|
lblAddress.Text = dr[1].ToString().ToUpper();
|
|
lblTelephone.Text = dr[2].ToString();
|
|
lblEmail.Text = dr[3].ToString();
|
|
string beginDate = dr[4].ToString();
|
|
string endDate = dr[5].ToString();
|
|
lblCharges.Text = Settings.Default.currrencyCode + " " + dr[11].ToString();
|
|
lblItemT.Text = Settings.Default.currrencyCode + " " + dr[10].ToString();
|
|
lblFrom.Value = Convert.ToDateTime(beginDate);
|
|
lblTo.Value = Convert.ToDateTime(endDate);
|
|
lblTotal.Text = Settings.Default.currrencyCode + " " + dr[6].ToString();
|
|
invoiceDetails.Rows.Add(i, dr[7].ToString().ToUpper(), dr[8].ToString(), dr[13].ToString(), Settings.Default.currrencyCode + " " + dr[9].ToString(),
|
|
dr[12].ToString(),dr[14].ToString());
|
|
i++;
|
|
}
|
|
dr.Close();
|
|
}));
|
|
cn.Close();
|
|
return 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
cn.Close();
|
|
ErrorLogging.WriteToFile(ex.ToString());
|
|
return 0;
|
|
}
|
|
}
|
|
public int updateEmail()
|
|
{
|
|
try
|
|
{
|
|
cn.Open();
|
|
cm = new SqlCommand("Update tblDeliveryRecipients set email = @email where deliveryID = @deliveryID", cn);
|
|
cm.Parameters.AddWithValue("@email", lblEmail.Text);
|
|
cm.Parameters.AddWithValue("@deliveryID", deliveryID);
|
|
cm.ExecuteNonQuery();
|
|
cn.Close();
|
|
return 1;
|
|
}
|
|
catch
|
|
{
|
|
cn.Close();
|
|
return 0;
|
|
}
|
|
}
|
|
public int cancelOrder()
|
|
{
|
|
try
|
|
{
|
|
cn.Open();
|
|
cm = new SqlCommand("Update tblDeliveryHead set status = @status where deliveryID = @deliveryID", cn);
|
|
cm.Parameters.AddWithValue("@status", "CANCELLED");
|
|
cm.Parameters.AddWithValue("@deliveryID", deliveryID);
|
|
cm.ExecuteNonQuery();
|
|
cn.Close();
|
|
return 1;
|
|
}
|
|
catch
|
|
{
|
|
cn.Close();
|
|
return 0;
|
|
}
|
|
}
|
|
public int confirmOrder()
|
|
{
|
|
cn.Open();
|
|
SqlTransaction tn = cn.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (DataGridViewRow row in invoiceDetails.Rows)
|
|
{
|
|
cm = new SqlCommand($"EXEC [dbo].[usp_confirm_delivery] @orderID = @order,@quantity = @newquantity,@pcode = @productID,@unit = @measure", cn, tn);
|
|
cm.Parameters.AddWithValue("@productID", row.Cells[4].Value.ToString());
|
|
cm.Parameters.AddWithValue("@newquantity", int.Parse(row.Cells[2].Value.ToString()));
|
|
cm.Parameters.AddWithValue("@measure", row.Cells[6].Value.ToString());
|
|
cm.Parameters.AddWithValue("@order", deliveryID);
|
|
cm.Parameters.AddWithValue("@status", "ASSIGNED TO TRUCK");
|
|
cm.ExecuteNonQuery();
|
|
}
|
|
cm = new SqlCommand("Update tblDeliveryHead set status = @status,dateCompleted = @date where deliveryID = @deliveryID", cn, tn);
|
|
cm.Parameters.AddWithValue("@status", "DELIVERED");
|
|
cm.Parameters.AddWithValue("@deliveryID", deliveryID);
|
|
cm.Parameters.AddWithValue("@date", DateTime.Now);
|
|
cm.ExecuteNonQuery();
|
|
tn.Commit();
|
|
cn.Close();
|
|
return 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLogging.WriteToFile(ex.ToString());
|
|
tn.Rollback();
|
|
cn.Close();
|
|
return 0;
|
|
}
|
|
}
|
|
private async void Button3_Click(object sender, EventArgs e)
|
|
{
|
|
holding.Visible = true;
|
|
Task<int> taskO = new Task<int>(cancelOrder);
|
|
string message = "Are you sure you would like to cancel this order ?";
|
|
string title = "Confirm action";
|
|
Confirmation yes_OR = new Confirmation(title, message);
|
|
yes_OR.BringToFront();
|
|
yes_OR.ShowDialog();
|
|
if (yes_OR.DialogResult == DialogResult.Yes)
|
|
{
|
|
taskO.Start();
|
|
int youin = await taskO;
|
|
if (youin == 1)
|
|
{
|
|
string titled = "Cancellation Successful";
|
|
string messaged = "Delivery order cancelled successfully";
|
|
NoAction noActiond = new NoAction(titled, messaged);
|
|
noActiond.BringToFront();
|
|
noActiond.ShowDialog();
|
|
lblStatus.Text = "CANCELLED";
|
|
lblStatus.ForeColor = Color.FromName("Crimson");
|
|
button2.Visible = false;
|
|
button3.Visible = false;
|
|
cancelled = true;
|
|
}
|
|
else
|
|
{
|
|
string titles = "Cancellation Failed";
|
|
string messages = "An error occurred while trying to cancel order";
|
|
NoAction noActions = new NoAction(titles, messages);
|
|
noActions.BringToFront();
|
|
noActions.ShowDialog();
|
|
}
|
|
}
|
|
holding.Visible = false;
|
|
}
|
|
private async void Button2_Click(object sender, EventArgs e)
|
|
{
|
|
holding.Visible = true;
|
|
string message = "Are you sure you would like to mark this order as delivered ?";
|
|
string title = "Confirm action";
|
|
Confirmation Confirmation = new Confirmation(title, message);
|
|
Confirmation.BringToFront();
|
|
Confirmation.ShowDialog();
|
|
if (Confirmation.DialogResult == DialogResult.Yes)
|
|
{
|
|
Task<int> task = new Task<int>(confirmOrder);
|
|
task.Start();
|
|
int result = await task;
|
|
if (result == 1)
|
|
{
|
|
string titled = "Confirmation Successful";
|
|
string messaged = "Order completed successfully";
|
|
NoAction noActiond = new NoAction(titled, messaged);
|
|
noActiond.BringToFront();
|
|
noActiond.ShowDialog();
|
|
button2.Visible = false;
|
|
button3.Visible = false;
|
|
lblStatus.Text = "DELIVERED";
|
|
lblStatus.ForeColor = Color.FromName("DarkGreen");
|
|
delivered = true;
|
|
}
|
|
else
|
|
{
|
|
string titled = "Confirmation failed";
|
|
string messaged = "Order confirmation failed due to an unexpected error!!!";
|
|
NoAction noActiond = new NoAction(titled, messaged);
|
|
noActiond.BringToFront();
|
|
noActiond.ShowDialog();
|
|
}
|
|
}
|
|
holding.Visible = false;
|
|
}
|
|
}
|
|
}
|