internal static List <DeliveryNote> GetDeliveryNotes() { List <DeliveryNote> deliverynotes = new List <DeliveryNote>(); SqlConnection con = new SqlConnection(MateFenyvConnectionString); con.Open(); SqlCommand cmd = new SqlCommand ("select * from DeliveryNotes"); cmd.Connection = con; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { int ID = int.Parse(dt.Rows[i]["Id"].ToString()); int foremanid = int.Parse(dt.Rows[i]["ForemanID"].ToString()); int orderid = int.Parse(dt.Rows[i]["OrderID"].ToString()); bool success = false; string succesString = dt.Rows[i]["Success"].ToString();; if (succesString.Equals("True")) { success = true; } DeliveryNote dn = new DeliveryNote(ID, success, foremanid, orderid); deliverynotes.Add(dn); } return(deliverynotes); }
public static void addDeliveryNote(DeliveryNote deliverynote) { try { SqlConnection con = new SqlConnection(MateFenyvConnectionString); con.Open(); int orderID = deliverynote.orderid; int foremanID = deliverynote.foremanid; bool success_bool = deliverynote.success; int success; if (success_bool) { success = 1; } else { success = 0; } SqlCommand cmd = new SqlCommand ( "INSERT INTO DeliveryNotes" + "(OrderID, ForemanID, Success) " + "VALUES(" + orderID + "," + foremanID + "," + success + ")" ); /*"DateOut, PalletQuantity, Cooled, Confirmed," + * " Terminal, OrderTime, Comment)" + "VALUES(" + customerID + "," + dispatcherID + ",'" + dateIn + "','" + dateOut + "'," + quantity + "," + cooled + "," + confirmed + "," + terminal + ",'" + orderTime + "','" + comment + "')" * );*/ cmd.Connection = con; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); } catch (Exception e) { if (e.GetHashCode() == 43527150) { Console.WriteLine("There is a delivery note with this ID."); Console.WriteLine(e.Message); } else { Console.WriteLine(e.Message); } } }
private async Task Process(TcpClient tcpClient) { string clientEndPoint = tcpClient.Client.RemoteEndPoint.ToString(); //ez adja vissza a kliens ip címét Console.WriteLine("Received connection request from " + clientEndPoint); try { //üzenet fogadása és válasz küldése NetworkStream networkStream = tcpClient.GetStream(); StreamReader reader = new StreamReader(networkStream); StreamWriter writer = new StreamWriter(networkStream); writer.AutoFlush = true; JavaScriptSerializer serializer = new JavaScriptSerializer(); while (true) { string requestStr = await reader.ReadLineAsync(); if (requestStr != null) { if (requestStr == "SetOrderTerminal") { requestStr = await reader.ReadLineAsync(); int id = Int32.Parse(requestStr); requestStr = await reader.ReadLineAsync(); int terminal = Int32.Parse(requestStr); DbHandler.setOrderTerminal(id, terminal); await writer.WriteLineAsync("success"); Console.WriteLine("SetOrderTerminal" + "ID" + id + "Terminal:" + terminal); } else if (requestStr == "SetOrderConfirmed") { requestStr = await reader.ReadLineAsync(); int id = Int32.Parse(requestStr); DbHandler.setConfirmedOrder(id); await writer.WriteLineAsync("success"); Console.WriteLine("OrderConfirmedWithID" + id); } else if (requestStr == "ListOfOrders") { List <Order> orders = DbHandler.GetOrders(); await writer.WriteLineAsync(serializer.Serialize(orders)); Console.WriteLine("Orders Request"); } else if (requestStr == "ListOfCustomers") { List <Customer> customers = DbHandler.GetCustomers(); await writer.WriteLineAsync(serializer.Serialize(customers)); Console.WriteLine("Customers Request"); } else if (requestStr == "ListOfDeliveryNotes") { List <DeliveryNote> deliverynotes = DbHandler.GetDeliveryNotes(); await writer.WriteLineAsync(serializer.Serialize(deliverynotes)); Console.WriteLine("DeliveryNotes Request"); } else if (requestStr.Equals("AddDeliveryNote")) { requestStr = await reader.ReadLineAsync(); DeliveryNote request = serializer.Deserialize <DeliveryNote>(requestStr); DbHandler.addDeliveryNote(request); DeliveryNote response = new DeliveryNote(); response = request; request.Print(); Console.WriteLine(request.ID.ToString()); await writer.WriteLineAsync(serializer.Serialize(response)); //Console.WriteLine(request.DateIn); } else if (requestStr.Equals("SetDeliveryNoteToSuccess")) { requestStr = await reader.ReadLineAsync(); int id = Int32.Parse(requestStr); DbHandler.SetDeliveryNoteToSuccess(id); await writer.WriteLineAsync("success"); Console.WriteLine("DeliveryNoteToSuccess " + id); } else if (requestStr.Equals("SetOrderOccupiedPlaces")) { requestStr = await reader.ReadLineAsync(); int id = Int32.Parse(requestStr); requestStr = await reader.ReadLineAsync(); int FirstOP = Int32.Parse(requestStr); requestStr = await reader.ReadLineAsync(); int LastOP = Int32.Parse(requestStr); DbHandler.SetOrderOccupiedPlaces(id, FirstOP, LastOP); await writer.WriteLineAsync("success"); Console.WriteLine("DeliveryNoteToSuccess " + id); } else { //CommObject request = serializer.Deserialize<CommObject>(requestStr); Console.WriteLine(requestStr); Order request = serializer.Deserialize <Order>(requestStr); Console.WriteLine(request.DateIn.ToLocalTime().ToString()); DbHandler.addOrder(request); request.Print(); Console.WriteLine(request.ID.ToString()); //Console.WriteLine(request.DateIn); Console.WriteLine("Received service request from: " + request.ToString()); Order response = Response(request); Console.WriteLine("Computed response is: " + response + "\n"); await writer.WriteLineAsync(serializer.Serialize(response)); } } else { Console.WriteLine("Connection closed, client: " + clientEndPoint); break; // Client closed connection } } tcpClient.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); if (tcpClient.Connected) { tcpClient.Close(); } Console.WriteLine("Connection closed, client: " + clientEndPoint); } }