public static List <Shipments> ViewShipmentsByCustomerName(string customerName)
        {
            DataTable        customerShipmentsTable = DataAccessLayer.ViewShipmentsByCustomerName(customerName);
            List <Shipments> customerShipmentsList  = new List <Shipments>();

            foreach (DataRow dr in customerShipmentsTable.Rows)
            {
                Shipments shipmentObject = new Shipments();
                shipmentObject.ShipmentId        = dr[0].ToString();
                shipmentObject.CustomerName      = dr[1].ToString();
                shipmentObject.StartLocation     = dr[2].ToString();
                shipmentObject.EndLocation       = dr[3].ToString();
                shipmentObject.ExpectedStartDate = DateTime.Parse(dr[4].ToString());
                shipmentObject.ActualStartDate   = DateTime.Parse(dr[5].ToString());
                shipmentObject.ExpectedEndDate   = DateTime.Parse(dr[6].ToString());
                shipmentObject.ActualEndDate     = DateTime.Parse(dr[7].ToString());
                customerShipmentsList.Add(shipmentObject);
            }
            return(customerShipmentsList);
        }
        public static int InsertShipmentDetails(Shipments shipmentObject)
        {
            int rowsAffected = 0;

            using (sqlConnection = new SqlConnection(connection))
            {
                sqlConnection.Open();
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Connection  = sqlConnection;
                    sqlCommand.CommandText = "insert into Shipments values(@shipmentId,@customername,@startLocation,@endLocation,@expectedStartDate,@actualStartDate,@expectedEndDate,@actualEndDate)";
                    sqlCommand.Parameters.AddWithValue("@shipmentId", shipmentObject.ShipmentId);
                    sqlCommand.Parameters.AddWithValue("@customername", shipmentObject.CustomerName);
                    sqlCommand.Parameters.AddWithValue("@startLocation", shipmentObject.StartLocation);
                    sqlCommand.Parameters.AddWithValue("@endLocation", shipmentObject.EndLocation);
                    sqlCommand.Parameters.AddWithValue("@expectedStartDate", shipmentObject.ExpectedStartDate);
                    sqlCommand.Parameters.AddWithValue("@actualStartDate", shipmentObject.ActualStartDate);
                    sqlCommand.Parameters.AddWithValue("@expectedEndDate", shipmentObject.ExpectedEndDate);
                    sqlCommand.Parameters.AddWithValue("@actualEndDate", shipmentObject.ActualEndDate);
                    rowsAffected = sqlCommand.ExecuteNonQuery();
                }
            }
            return(rowsAffected);
        }
 public static int AddCustomerDetails(Shipments shipments)
 {
     return(DataAccessLayer.InsertShipmentDetails(shipments));
 }
Example #4
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("\n Enter Your Choice \n");
                    Console.WriteLine(" 1. Insert Logistics Details\n 2. View All Logistics Details \n 3. View Logistics details of a customer \n 4. Exit");
                    int choice = Convert.ToInt32(Console.ReadLine());

                    switch (choice)
                    {
                    case 1:
                    {
                        Shipments shipmentObject = new Shipments();
                        Console.WriteLine("Enter the Shipment Id");
                        string shipmentId = Console.ReadLine();
                        shipmentObject.ShipmentId = shipmentId;

                        Console.WriteLine("Enter the Customer Name");
                        string customerName = Console.ReadLine();
                        shipmentObject.CustomerName = customerName;

                        Console.WriteLine("Enter the Start Location");
                        string startLocation = Console.ReadLine();
                        shipmentObject.StartLocation = startLocation;

                        Console.WriteLine("Enter the End Location");
                        string endLocation = Console.ReadLine();
                        shipmentObject.EndLocation = endLocation;

                        Console.WriteLine("Enter the ExpectedStartDate");
                        string expectedStartDate = Console.ReadLine();
                        shipmentObject.ExpectedStartDate = DateTime.Parse(expectedStartDate);

                        Console.WriteLine("Enter the ActualStartDate");
                        string actualStartDate = Console.ReadLine();
                        shipmentObject.ActualStartDate = DateTime.Parse(actualStartDate);

                        Console.WriteLine("Enter the ExpectedEndDate");
                        string expectedEndDate = Console.ReadLine();
                        shipmentObject.ExpectedEndDate = DateTime.Parse(expectedEndDate);

                        Console.WriteLine("Enter the ActualEndDate");
                        string actualEndDate = Console.ReadLine();
                        shipmentObject.ActualEndDate = DateTime.Parse(actualEndDate);

                        int rowsAffected = BusinessLogicLayer.AddCustomerDetails(shipmentObject);
                        if (rowsAffected > 0)
                        {
                            Console.WriteLine("Shipment Items inserted successfully");
                        }
                        else
                        {
                            Console.WriteLine("An error occurred");
                        }

                        break;
                    }

                    case 2:
                    {
                        List <Shipments> shipmentDetails = BusinessLogicLayer.ViewShipmentDetails();
                        foreach (var item in shipmentDetails)
                        {
                            Console.WriteLine(item.ShipmentId + "\t" + item.CustomerName + "\t" + item.StartLocation + "\t" + item.EndLocation + "\t" + item.ExpectedStartDate + "\t" + item.ActualStartDate + "\t" + item.ExpectedEndDate + "\t" + item.ActualEndDate);
                        }
                        break;
                    }

                    case 3:
                    {
                        Console.WriteLine("Enter the customer name");
                        string           customerName    = Console.ReadLine();
                        List <Shipments> shipmentDetails = BusinessLogicLayer.ViewShipmentsByCustomerName(customerName);
                        foreach (var item in shipmentDetails)
                        {
                            Console.WriteLine(item.ShipmentId + "\t" + item.CustomerName + "\t" + item.StartLocation + "\t" + item.EndLocation + "\t" + item.ExpectedStartDate + "\t" + item.ActualStartDate + "\t" + item.ExpectedEndDate + "\t" + item.ActualEndDate);
                        }
                        break;
                    }

                    case 4:
                    {
                        Console.WriteLine("Exiting the application");
                        Environment.Exit(0);
                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Please enter a valid Choice");
                        break;
                    }
                    }

                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
 public static int AddCustomerDetails(Shipments shipments)
 {
     /*
      *   Please fill your code here
      */
 }
Example #6
0
 public static int InsertShipmentDetails(Shipments shipmentObject)
 {
     /*
      *   Please fill your code here
      */
 }