public bool addNewOrder(Order newOrder) { DatabaseOperations operations = new DatabaseOperations(); try { int paperTypeID = int.Parse(operations.executeSelectQuery("SELECT PaperTypeID FROM PaperType WHERE PaperTypeName='" + newOrder.PaperType + "'").Rows[0][0].ToString()); int statusTypeID = int.Parse(operations.executeSelectQuery("SELECT OrderStatusID FROM OrderStatus WHERE OrderStatusName='" + newOrder.OrderStatus + "'").Rows[0][0].ToString()); DataTable customerDetails = operations.executeSelectQuery("SELECT * FROM CustomerDetails WHERE CustomerName='" + newOrder.Customer.Name + "' AND CustomerContactNumber=" + newOrder.Customer.ContactNumber); if (customerDetails.Rows.Count == 0) { DataTable allCustomerDetails = operations.executeSelectQuery("SELECT * FROM CustomerDetails"); if (allCustomerDetails.Rows.Count == 0) { operations.executeInsUpdDelQuery("INSERT INTO CustomerDetails (CustomerID, CustomerName, CustomerAddress, CustomerContactNumber) VALUES (" + 1 + ",'" + newOrder.Customer.Name + "','" + newOrder.Customer.Address + "," + newOrder.Customer.ContactNumber + ")"); newOrder.Customer.ID = 1; } else { int lastCustomerID = (int)allCustomerDetails.Rows[allCustomerDetails.Rows.Count - 1][0]; operations.executeInsUpdDelQuery("INSERT INTO CustomerDetails (CustomerID, CustomerName, CustomerAddress, CustomerContactNumber) VALUES (" + (lastCustomerID + 1) + ",'" + newOrder.Customer.Name + "','" + newOrder.Customer.Address + "'," + newOrder.Customer.ContactNumber + ")"); newOrder.Customer.ID = lastCustomerID + 1; } int i = operations.executeInsUpdDelQuery("INSERT INTO OrderDetails (OrderID, CustomerID, DesignID, PaperTypeID, OrderStatusID, Quantity, Size, DeliveryDate, PerProductCost, AdvancePayment, OrderDelivered, Color) VALUES (" + newOrder.OrderID + "," + newOrder.Customer.ID + ",'" + newOrder.DesignID + "'," + paperTypeID + "," + statusTypeID + "," + newOrder.Quantity + ",'" + newOrder.Size + "','" + newOrder.DeliveryDate + "'," + newOrder.UnitPrice + "," + newOrder.AdvancePayment + ",0,'" + newOrder.Color + "')"); int j = operations.executeUpdImageQuery("OrderDetails", "FinalDesignToBePrinted", newOrder.FinalizedDesign, "OrderID", newOrder.OrderID.ToString()); if (i == 1 && j == 1) { return(true); } else { return(false); } } else { newOrder.Customer.ID = int.Parse(customerDetails.Rows[0][0].ToString()); int i = operations.executeInsUpdDelQuery("INSERT INTO OrderDetails (OrderID, CustomerID, DesignID, PaperTypeID, OrderStatusID, Quantity, Size, DeliveryDate, PerProductCost, AdvancePayment, OrderDelivered, Color) VALUES (" + newOrder.OrderID + "," + newOrder.Customer.ID + ",'" + newOrder.DesignID + "'," + paperTypeID + "," + statusTypeID + "," + newOrder.Quantity + ",'" + newOrder.Size + "','" + newOrder.DeliveryDate + "'," + newOrder.UnitPrice + "," + newOrder.AdvancePayment + ",0,'" + newOrder.Color + "')"); int j = operations.executeUpdImageQuery("OrderDetails", "FinalDesignToBePrinted", newOrder.FinalizedDesign, "OrderID", newOrder.OrderID.ToString()); if (i == 1 && j == 1) { return(true); } else { return(false); } } } catch (Exception ex) { return(false); } }
public bool editOrder(Order order) { DatabaseOperations operations = new DatabaseOperations(); int paperTypeID = int.Parse(operations.executeSelectQuery("SELECT PaperTypeID FROM PaperType WHERE PaperTypeName='" + order.PaperType + "'").Rows[0][0].ToString()); int statusTypeID = int.Parse(operations.executeSelectQuery("SELECT OrderStatusID FROM OrderStatus WHERE OrderStatusName='" + order.OrderStatus + "'").Rows[0][0].ToString()); int i = operations.executeInsUpdDelQuery("UPDATE OrderDetails SET DesignID='" + order.DesignID + "', PaperTypeID=" + paperTypeID + ", Size='" + order.Size + "', OrderStatusID=" + statusTypeID + ", Quantity=" + order.Quantity + ", DeliveryDate='" + order.DeliveryDate.ToString() + "', PerProductCost=" + order.UnitPrice + ", AdvancePayment=" + order.AdvancePayment + " WHERE OrderID=" + order.OrderID); int j = 1; if (order.FinalizedDesign != "Click Here") { j = operations.executeUpdImageQuery("OrderDetails", "FinalDesignToBePrinted", order.FinalizedDesign, "OrderID", order.OrderID.ToString()); } if (i == 1 && j == 1) { return(true); } else { return(false); } }
public bool saveDesign(Design d) { try { DatabaseOperations operations = new DatabaseOperations(); int paperTypeID = int.Parse(operations.executeSelectQuery("SELECT PaperTypeID FROM PaperType WHERE PaperType.PaperTypeName='" + d.DesignPaperType + "'").Rows[0][0].ToString()); int productID = int.Parse(operations.executeSelectQuery("SELECT ProductID FROM Product WHERE Product.ProductName='" + d.ProductName + "'").Rows[0][0].ToString()); int i = operations.executeInsUpdDelQuery("INSERT INTO Design (DesignID, DesignName, ProductID, PaperTypeID, Size) VALUES('" + d.DesignID + "','" + d.DesignName + "'," + productID + "," + paperTypeID + ",'" + d.DesignSize + "')"); int j = operations.executeUpdImageQuery("Design", "DesignFile", d.DesignFilePath, "DesignID", d.DesignID); if (i == 1 && j == 1) { return(true); } else { return(false); } } catch (Exception ex) { return(false); } }