private async void Register_Click(object sender, EventArgs e) { if (!(await IsValidTrackingIds())) { error.SetError(TrackingIdCount, "Some tracking ids already exist in database."); return; } else { error.SetError(TrackingIdCount, ""); } try { foreach (var item in TrackingIds) { InwardSingleShipment si = new InwardSingleShipment() { CourierName = CourierName.Text, Date = ShipmentDate.Value, ItemCondition = "N/A", ItemName = "N/A", Remarks = Remarks.Text, TrackingId = item, ShipmentType = "Inward", CustomerName = "N/A", Amount = "N/A", PaymentType = "N/A" }; ShipmentLibrary.InsertInwardSingleShipment(si); } Notification.Show("Registered", Notification.Type.Success); Clear(); inwardSingleShipmentBindingSource.DataSource = await ShipmentLibrary.GetInwardShipmentsAsync(); dg.ClearSelection(); } catch (Exception ex) { MessageBox.Show($"Failed to register shipments due to:\nException Type:{ex.GetType()}\nMessage:{ex.Message}", ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void InsertInwardSingleShipment(InwardSingleShipment si) { List <SqlParameter> parameters = new List <SqlParameter>() { new SqlParameter("@date ", si.Date), new SqlParameter("@tracking ", si.TrackingId), new SqlParameter("@courier ", si.CourierName), new SqlParameter("@item ", si.ItemName), new SqlParameter("@condition", si.ItemCondition), new SqlParameter("@remarks ", si.Remarks), new SqlParameter("@type ", si.ShipmentType), new SqlParameter("@customer ", si.CustomerName), new SqlParameter("@payment ", si.PaymentType), new SqlParameter("@amount ", si.Amount), }; Access.ExecuteProcedure("[dbo].[InsertShipment]", parameters.ToArray()); }
private async void Register_Click(object sender, EventArgs e) { try { InwardSingleShipment si = new InwardSingleShipment() { CourierName = CourierName.Text, Date = ShipmentDate.Value, ItemCondition = ItemCondition.Text, ItemName = ItemName.Text, Remarks = Remarks.Text, TrackingId = TrackingId.Text, ShipmentType = "Inward", CustomerName = "N/A", PaymentType = "N/A", Amount = "N/A" }; ShipmentLibrary.InsertInwardSingleShipment(si); Notification.Show("Shipment registered", Notification.Type.Success); Clear(); inwardSingleShipmentBindingSource.DataSource = await ShipmentLibrary.GetInwardShipmentsAsync(); dg.ClearSelection(); } catch (Exception ex) { MessageBox.Show($"Failed to register shipment due to:\nException Type:{ex.GetType()}\nMessage:{ex.Message}", ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static async Task <InwardSingleShipment[]> GetInwardSingleShipmentsAsync(string command, SqlParameter[] parameters = null) { List <InwardSingleShipment> col = new List <InwardSingleShipment>(); using (SqlConnection cnn = await DB.GetSqlConnectionAsync()) { SqlCommand cmd = new SqlCommand(command, cnn); if (parameters != null) { cmd.Parameters.AddRange(parameters); } SqlDataReader reader = await cmd.ExecuteReaderAsync(); if (reader.HasRows) { while (await reader.ReadAsync()) { InwardSingleShipment ship = new InwardSingleShipment() { Date = (DateTime)reader["ShipmentDate"], ItemCondition = (string)reader["ItemCondition"], ItemName = (string)reader["ItemName"], Remarks = (string)reader["Remarks"], TrackingId = (string)reader["TrackingId"], CourierName = (string)reader["CourierName"], ShipmentType = (string)reader["ShipmentType"], CustomerName = (string)reader["CustomerName"], Amount = (string)reader["Amount"], PaymentType = (string)reader["PaymentType"] }; col.Add(ship); } } } return(col.ToArray()); }