public List <SayurboxInventory> CekItemsAvaliability() { //string JSONstring = OperationContext.Current.RequestContext.RequestMessage.ToString(); //XmlDocument xmlDoc = new XmlDocument(); //xmlDoc.LoadXml(JSONstring); //string storer = xmlDoc.GetElementsByTagName("storer")[0].InnerText; //string Search_Parameter = xmlDoc.GetElementsByTagName("Search_Parameter")[0].InnerText; //string Search_Value = xmlDoc.GetElementsByTagName("Search_Value")[0].InnerText; //int da_page = Convert.ToInt32(xmlDoc.GetElementsByTagName("Page_Number")[0].InnerText); List <SayurboxInventory> list = new List <SayurboxInventory>(); SqlConnection DBConn = new SqlConnection("Server=127.0.0.1;Database=Coba_Sayurbox_Db;UID=sa;PWD=P4ssw0rD;"); //SqlConnection DBConn = new SqlConnection("UID=sa;PWD=P4ssw0rD;Database=Coba_Sayurbox_Db;Data Source = Coba_Sayurbox_Db.mdf"); //SqlConnection DBConn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=\bin\Debug\Coba_Sayurbox_Db.mdf;Connect Timeout=30;User Instance=True;UID=sa;PWD=P4ssw0rD;Database=Coba_Sayurbox_Db;"); //SqlConnection DBConn = new SqlConnection(@"Server=.\SQLExpress;AttachDbFilename=\bin\Debug\Coba_Sayurbox_Db.mdf;Database=Coba_Sayurbox_Db;Trusted_Connection=Yes;UID=sa;PWD=P4ssw0rD;"); SqlCommand DBCmd = new SqlCommand(); SqlDataReader DBDR; SqlDataAdapter DA; DataTable DT; DataSet DS; string QUERY; if (DBConn.State == ConnectionState.Closed) { DBConn.Open(); } DBCmd.Connection = DBConn; DBCmd.CommandText = "SELECT * from Da_Inventory"; //DBCmd.Parameters.AddWithValue("storer", storer); //DBCmd.Parameters.AddWithValue("da_start", (da_page - 1) * da_interval); //DBCmd.Parameters.AddWithValue("da_end", da_page * da_interval); DBDR = DBCmd.ExecuteReader(); while (DBDR.Read()) { list.Add(new SayurboxInventory() { Id = Convert.ToInt32(DBDR["ID"]), SayurName = DBDR["ItemName"].ToString(), Qty = Convert.ToInt32(DBDR["ItemQty"]), }); } DBDR.Close(); DBConn.Close(); return(list); }
public List <SayurboxOrderRequestExchange> ReceiveOpenRequest() { //I am not 100% sure about this one so I assume the logic for this one is similar to online driver //I am also not sure whether the request is assigned a request automatically or not so I make the driver able to see all open order and can choose which order they want to tackle List <SayurboxOrderRequestExchange> list = new List <SayurboxOrderRequestExchange>(); SqlConnection DBConn = new SqlConnection("Server=127.0.0.1;Database=Coba_Sayurbox_Db;UID=sa;PWD=P4ssw0rD;"); SqlCommand DBCmd = new SqlCommand(); SqlDataReader DBDR; SqlDataAdapter DA; DataTable DT; DataSet DS; string QUERY; if (DBConn.State == ConnectionState.Closed) { DBConn.Open(); } DBCmd.Connection = DBConn; DBCmd.CommandText = "SELECT * from DaOrderRequest where Status='Open'"; DBDR = DBCmd.ExecuteReader(); while (DBDR.Read()) { list.Add(new SayurboxOrderRequestExchange() { OrderId = Convert.ToInt32(DBDR["OrderId"]), CustomerId = Convert.ToInt32(DBDR["CustomerId"]), CustomerLat = Convert.ToDouble(DBDR["CustomerLat"]), CustomerLon = Convert.ToDouble(DBDR["CustomerLon"]), DriverAccept = DBDR["DriverAccept"].ToString(), CustomerAccept = DBDR["CustomerAccept"].ToString(), OrderInventoryCode = DBDR["OrderInventoryCode"].ToString(), Status = DBDR["Status"].ToString(), }); } DBDR.Close(); DBConn.Close(); return(list); }
public string GetDriverLocationOrder() { string JSONstring = OperationContext.Current.RequestContext.RequestMessage.ToString(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(JSONstring); int OrderId = Convert.ToInt32(xmlDoc.GetElementsByTagName("OrderId")[0].InnerText); int CustomerId = Convert.ToInt32(xmlDoc.GetElementsByTagName("CustomerId")[0].InnerText); List <SayurboxOrderRequestExchange> list = new List <SayurboxOrderRequestExchange>(); SqlConnection DBConn = new SqlConnection("Server=127.0.0.1;Database=Coba_Sayurbox_Db;UID=sa;PWD=P4ssw0rD;"); SqlCommand DBCmd = new SqlCommand(); SqlDataReader DBDR; SqlDataAdapter DA; DataTable DT; DataSet DS; string QUERY; if (DBConn.State == ConnectionState.Closed) { DBConn.Open(); } DBCmd.Connection = DBConn; DBCmd.CommandText = "SELECT * from DaOrderRequest where OrderId=@Da_OrderId AND CustomerId=@Da_CustomerId"; DBCmd.Parameters.AddWithValue("Da_OrderId", OrderId); DBCmd.Parameters.AddWithValue("Da_CustomerId", CustomerId); DBDR = DBCmd.ExecuteReader(); string da_location = ""; while (DBDR.Read()) { da_location += "Driver Location is LAT:" + DBDR["DriverLat"].ToString() + " LON:" + DBDR["DriverLon"].ToString(); } DBDR.Close(); DBConn.Close(); return(da_location); }
public string OrderForCustomer() { string JSONstring = OperationContext.Current.RequestContext.RequestMessage.ToString(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(JSONstring); List <SayurboxInventoryInput> Da_inputs = new List <SayurboxInventoryInput>(); int da_paling_awal = 0; bool keep_going = true; while (keep_going == true) { try { Da_inputs.Add(new SayurboxInventoryInput() { Id = Convert.ToInt32(xmlDoc.GetElementsByTagName("Id")[da_paling_awal].InnerText), SayurName = xmlDoc.GetElementsByTagName("SayurName")[da_paling_awal].InnerText, Qty = Convert.ToInt32(xmlDoc.GetElementsByTagName("Qty")[da_paling_awal].InnerText), CustomerId = Convert.ToInt32(xmlDoc.GetElementsByTagName("CustomerId")[da_paling_awal].InnerText), }); da_paling_awal++; } catch (Exception e) { keep_going = false; } } List <SayurboxInventory> list = new List <SayurboxInventory>(); SqlConnection DBConn = new SqlConnection("Server=127.0.0.1;Database=Coba_Sayurbox_Db;UID=sa;PWD=P4ssw0rD;"); SqlCommand DBCmd = new SqlCommand(); SqlDataReader DBDR; SqlDataAdapter DA; DataTable DT; DataSet DS; string QUERY; if (DBConn.State == ConnectionState.Closed) { DBConn.Open(); } DBCmd.Connection = DBConn; DBCmd.CommandText = "SELECT * from Da_Inventory where ID=@da_idsayur0"; DBCmd.Parameters.AddWithValue("da_idsayur0", Da_inputs[0].Id); if (Da_inputs.Count > 1) { for (int i = 1; i < Da_inputs.Count; i++) { DBCmd.CommandText += " OR ID=@da_idsayur" + i; DBCmd.Parameters.AddWithValue("da_idsayur" + i, Da_inputs[i].Id); } } //DBCmd.Parameters.AddWithValue("storer", storer); //DBCmd.Parameters.AddWithValue("da_start", (da_page - 1) * da_interval); //DBCmd.Parameters.AddWithValue("da_end", da_page * da_interval); DBDR = DBCmd.ExecuteReader(); while (DBDR.Read()) { list.Add(new SayurboxInventory() { Id = Convert.ToInt32(DBDR["ID"]), SayurName = DBDR["ItemName"].ToString(), Qty = Convert.ToInt32(DBDR["ItemQty"]), }); } DBDR.Close(); bool Available = true; for (int i = 1; i < Da_inputs.Count; i++) { for (int x = 1; x < list.Count; x++) { if (Da_inputs[i].Id == list[x].Id) { int cek_da_thing = list[x].Qty - Da_inputs[i].Qty; if (cek_da_thing < 0) { Available = false; } } } } string da_message = "this is message"; if (Available == true) { da_message = "yes the stock is available"; } else if (Available == false) { da_message = "no the stock is not available"; } if (da_message == "yes the stock is available") { for (int i = 0; i < Da_inputs.Count; i++) { for (int x = 0; x < list.Count; x++) { if (Da_inputs[i].Id == list[x].Id) { DBCmd.CommandText = " UPDATE Da_Inventory set ItemQty=@da_qty" + i + " where ID=@da_idsayurForOrder" + i; DBCmd.Parameters.AddWithValue("da_qty" + i, (list[x].Qty - Da_inputs[i].Qty)); DBCmd.Parameters.AddWithValue("da_idsayurForOrder" + i, Da_inputs[i].Id); int Da_Affected = DBCmd.ExecuteNonQuery(); } } } da_message = "Order success"; } DBConn.Close(); return(da_message); //JSONstring.Length; ; }