Exemplo n.º 1
0
		public string SendOrderPrint(OrderInformation orderInfo, int CustID, string CustFullName, bool print)
		{
			int num = 0;
			ArrayList list = new ArrayList();
			ArrayList list2 = new ArrayList();
			string[] billDetailID = null;
			if (orderInfo == null)
			{
				return "No data";
			}
			SqlConnection connection = null;
			SqlTransaction transaction = null;
			try
			{
				string str;
				connection = ConnectDB.GetConnection();
				transaction = connection.BeginTransaction();
				SqlCommand command = new SqlCommand();
				command.Connection = connection;
				command.Transaction = transaction;
				command.CommandType = CommandType.StoredProcedure;
				if (orderInfo.OrderID == 0)
				{
					command.CommandText = "insertOrder";
					num = 1;
				}
				else
				{
					command.CommandText = "updateOrder";
					command.Parameters.Add("@orderID", SqlDbType.Int).Value = orderInfo.OrderID;
				}
				command.Parameters.Add("@orderTime", SqlDbType.DateTime).Value = orderInfo.OrderTime;
				command.Parameters.Add("@tableID", SqlDbType.Int).Value = orderInfo.TableID;
				command.Parameters.Add("@employeeID", SqlDbType.Int).Value = orderInfo.EmployeeID;
				command.Parameters.Add("@numberOfGuest", SqlDbType.Int).Value = orderInfo.NumberOfGuest;
				SqlParameter parameter6 = command.Parameters.Add("@closeOrderDate", SqlDbType.DateTime);
				if (orderInfo.CloseOrderDate.CompareTo(AppParameter.MinDateTime) <= 0)
				{
					parameter6.Value = DBNull.Value;
				}
				else
				{
					parameter6.Value = orderInfo.CloseOrderDate;
				}
				SqlParameter parameter7 = command.Parameters.Add("@result", SqlDbType.Int);
				parameter7.Direction = ParameterDirection.Output;
				command.ExecuteNonQuery();
				orderInfo.OrderID = (int) parameter7.Value;
				if (orderInfo.OrderID == 0)
				{
					transaction.Rollback();
					return "Can't insert order info";
				}
				list2.Add(orderInfo.OrderID);
				if (orderInfo.Bills != null)
				{
					command.Parameters.Clear();
					SqlParameter parameter8 = command.Parameters.Add("@orderBillID", SqlDbType.Int);
					SqlParameter parameter9 = command.Parameters.Add("@billID", SqlDbType.Int);
					SqlParameter parameter = command.Parameters.Add("@orderID", SqlDbType.Int);
					SqlParameter parameter4 = command.Parameters.Add("@employeeID", SqlDbType.Int);
					SqlParameter parameter10 = command.Parameters.Add("@closeBillDate", SqlDbType.DateTime);
					parameter7 = command.Parameters.Add("@result", SqlDbType.Int);
					parameter7.Direction = ParameterDirection.Output;
					SqlCommand command2 = new SqlCommand();
					command2.Connection = connection;
					command2.Transaction = transaction;
					command2.CommandType = CommandType.StoredProcedure;
					SqlParameter parameter11 = command2.Parameters.Add("@billDetailID", SqlDbType.Int);
					SqlParameter parameter12 = command2.Parameters.Add("@orderBillID", SqlDbType.Int);
					SqlParameter parameter13 = command2.Parameters.Add("@menuID", SqlDbType.Int);
					SqlParameter parameter14 = command2.Parameters.Add("@unit", SqlDbType.Int);
					SqlParameter parameter15 = command2.Parameters.Add("@status", SqlDbType.TinyInt);
					SqlParameter parameter16 = command2.Parameters.Add("@message", SqlDbType.NText);
					SqlParameter parameter17 = command2.Parameters.Add("@serveTime", SqlDbType.DateTime);
					SqlParameter parameter18 = command2.Parameters.Add("@cancelReasonID", SqlDbType.Int);
					SqlParameter parameter19 = command2.Parameters.Add("@employeeID", SqlDbType.Int);
					SqlParameter parameter20 = command2.Parameters.Add("@result", SqlDbType.Int);
					parameter20.Direction = ParameterDirection.Output;
					SqlCommand command3 = new SqlCommand();
					command3.Connection = connection;
					command3.Transaction = transaction;
					command3.CommandType = CommandType.StoredProcedure;
					SqlParameter parameter21 = command3.Parameters.Add("@billDetailID", SqlDbType.Int);
					SqlParameter parameter22 = command3.Parameters.Add("@choiceID", SqlDbType.Int);
					command3.Parameters.Add("@result", SqlDbType.Int).Direction = ParameterDirection.Output;
					for (int i = 0; i < orderInfo.Bills.Length; i++)
					{
						OrderBill bill = orderInfo.Bills[i];
						if (bill.OrderBillID == 0)
						{
							command.CommandText = "insertOrderBill";
							if (command.Parameters.Contains(parameter8))
							{
								command.Parameters.Remove(parameter8);
							}
							if (command.Parameters.Contains(parameter10))
							{
								command.Parameters.Remove(parameter10);
							}
							if (!command.Parameters.Contains(parameter))
							{
								command.Parameters.Add(parameter);
							}
							parameter.Value = orderInfo.OrderID;
							if (num != 1)
							{
								num = 2;
							}
						}
						else
						{
							command.CommandText = "updateOrderBill";
							if (!command.Parameters.Contains(parameter8))
							{
								command.Parameters.Add(parameter8);
							}
							if (!command.Parameters.Contains(parameter10))
							{
								command.Parameters.Add(parameter10);
							}
							if (command.Parameters.Contains(parameter))
							{
								command.Parameters.Remove(parameter);
							}
							parameter8.Value = bill.OrderBillID;
							if (bill.CloseBillDate.CompareTo(AppParameter.MinDateTime) <= 0)
							{
								parameter10.Value = DBNull.Value;
							}
							else
							{
								parameter10.Value = bill.CloseBillDate;
							}
						}
						parameter4.Value = bill.EmployeeID;
						parameter9.Value = bill.BillID;
						command.ExecuteNonQuery();
						bill.OrderBillID = (int) parameter7.Value;
						if (bill.OrderBillID == 0)
						{
							transaction.Rollback();
							return "Can't insert bill";
						}
						if (bill.Items != null)
						{
							parameter12.Value = bill.OrderBillID;
							for (int j = 0; j < bill.Items.Length; j++)
							{
								OrderBillItem item = bill.Items[j];
								if (item.BillDetailID == 0)
								{
									command2.CommandText = "insertOrderBillDetail";
									if (command2.Parameters.Contains(parameter11))
									{
										command2.Parameters.Remove(parameter11);
									}
									if (command2.Parameters.Contains(parameter15))
									{
										command2.Parameters.Remove(parameter15);
									}
									if (command2.Parameters.Contains(parameter17))
									{
										command2.Parameters.Remove(parameter17);
									}
									if (command2.Parameters.Contains(parameter18))
									{
										command2.Parameters.Remove(parameter18);
									}
									if ((num != 1) && (num != 2))
									{
										num = 3;
									}
								}
								else
								{
									command2.CommandText = "updateOrderBillDetail";
									if (!command2.Parameters.Contains(parameter11))
									{
										command2.Parameters.Add(parameter11);
									}
									if (!command2.Parameters.Contains(parameter15))
									{
										command2.Parameters.Add(parameter15);
									}
									if (!command2.Parameters.Contains(parameter17))
									{
										command2.Parameters.Add(parameter17);
									}
									if (!command2.Parameters.Contains(parameter18))
									{
										command2.Parameters.Add(parameter18);
									}
									parameter11.Value = item.BillDetailID;
									parameter15.Value = item.Status;
									if (item.ServeTime.CompareTo(AppParameter.MinDateTime) <= 0)
									{
										parameter17.Value = DBNull.Value;
									}
									else
									{
										parameter17.Value = item.ServeTime;
									}
									if (item.CancelReasonID == 0)
									{
										parameter18.Value = DBNull.Value;
									}
									else
									{
										parameter18.Value = item.CancelReasonID;
									}
								}
								parameter13.Value = item.MenuID;
								parameter14.Value = item.Unit;
								if ((item.Message == null) || (item.Message.Length == 0))
								{
									parameter16.Value = DBNull.Value;
								}
								else
								{
									parameter16.Value = item.Message;
								}
								parameter19.Value = item.EmployeeID;
								command2.ExecuteNonQuery();
								item.BillDetailID = (int) parameter20.Value;
								if (item.BillDetailID == 0)
								{
									transaction.Rollback();
									return "Can't insert item";
								}
								switch (num)
								{
									case 1:
									case 2:
									case 3:
										if ((item.Status != 0) || AppParameter.IsDemo())
										{
											list.Add(item.BillDetailID.ToString());
										}
										if (num == 3)
										{
											num = 0;
										}
										break;

									default:
										if (((command2.CommandText == "updateOrderBillDetail") && item.ChangeFlag) && ((item.Status != 0) || AppParameter.IsDemo()))
										{
											list.Add(item.BillDetailID.ToString());
										}
										break;
								}
								command3.CommandText = "deleteOrderBillOption";
								if (command3.Parameters.Contains(parameter22))
								{
									command3.Parameters.Remove(parameter22);
								}
								parameter21.Value = item.BillDetailID;
								command3.ExecuteNonQuery();
								if (!item.DefaultOption && (item.ItemChoices != null))
								{
									command3.Parameters.Add(parameter22);
									for (int k = 0; k < item.ItemChoices.Length; k++)
									{
										OrderItemChoice choice = item.ItemChoices[k];
										command3.CommandText = "insertOrderBillOption";
										parameter22.Value = choice.ChoiceID;
										command3.ExecuteNonQuery();
										if (((int) parameter20.Value) == 0)
										{
											transaction.Rollback();
											return "Can't insert choice";
										}
									}
								}
							}
						}
						if (num == 2)
						{
							num = 0;
						}
					}
				}
				transaction.Commit();
				transaction = null;
				if ((CustFullName != null) && (CustFullName != ""))
				{
					str = this.SendTakeOut(orderInfo.OrderID, CustID, CustFullName);
					if (str != null)
					{
						return str;
					}
				}
				if (print)
				{
					billDetailID = (string[]) list.ToArray(typeof(string));
					this.PrintKitchen(billDetailID);
					for (int m = 0; m < list2.Count; m++)
					{
						OrderInformation.OrderPrintKitchen((int) list2[m]);
					}
				}
				str = this.CheckOrderClose(orderInfo.OrderID);
				if (str != null)
				{
					return str;
				}
			}
			catch (Exception exception)
			{
				if (transaction != null)
				{
					transaction.Rollback();
				}
				return exception.ToString();
			}
			finally
			{
				if (connection != null)
				{
					connection.Close();
				}
			}
			return orderInfo.OrderID.ToString();
		}
Exemplo n.º 2
0
		public OrderInformation GetOrder(int tableID)
		{
			SqlConnection connection = null;
			OrderInformation information2;
			try
			{
				int num;
				int num2;
				int num3;
				connection = ConnectDB.GetConnection();
				SqlCommand selectCommand = new SqlCommand("getOrderInformation", connection);
				selectCommand.CommandType = CommandType.StoredProcedure;
				selectCommand.Parameters.Add("@tableID", SqlDbType.Int).Value = tableID;
				SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
				DataSet dataSet = new DataSet();
				adapter.Fill(dataSet);
				DataTable table = dataSet.Tables[0];
				if (table.Rows.Count <= 0)
				{
					return null;
				}
				OrderInformation information = new OrderInformation();
				DataRow row = table.Rows[0];
				information.OrderID = (int) row["OrderID"];
				information.OrderTime = (DateTime) row["OrderTime"];
				information.TableID = (int) row["TableID"];
				information.EmployeeID = (int) row["EmployeeID"];
				information.NumberOfGuest = (int) row["NumberOfGuest"];
				information.CloseOrderDate = (row["CloseOrderDate"] is DBNull) ? AppParameter.MinDateTime : ((DateTime) row["CloseOrderDate"]);
				information.CreateDate = (DateTime) row["CreateDate"];
				table = dataSet.Tables[1];
				if (table.Rows.Count <= 0)
				{
					information.Bills = null;
					return information;
				}
				information.Bills = new OrderBill[table.Rows.Count];
				for (num = 0; num < table.Rows.Count; num++)
				{
					information.Bills[num] = new OrderBill();
					row = table.Rows[num];
					information.Bills[num].OrderBillID = (int) row["OrderBillID"];
					information.Bills[num].BillID = (int) row["BillID"];
					information.Bills[num].EmployeeID = (int) row["EmployeeID"];
					information.Bills[num].Items = null;
					information.Bills[num].CloseBillDate = (row["CloseBillDate"] is DBNull) ? AppParameter.MinDateTime : ((DateTime) row["CloseBillDate"]);
				}
				table = dataSet.Tables[2];
				if (table.Rows.Count <= 0)
				{
					return information;
				}
				for (num = 0; num < table.Rows.Count; num++)
				{
					row = table.Rows[num];
					int num5 = (int) row["OrderBillID"];
					num2 = 0;
					while (num2 < information.Bills.Length)
					{
						if (information.Bills[num2].OrderBillID == num5)
						{
							OrderBill bill = information.Bills[num2];
							if (bill.Items == null)
							{
								bill.Items = new OrderBillItem[1];
							}
							else
							{
								OrderBillItem[] items = bill.Items;
								bill.Items = new OrderBillItem[bill.Items.Length + 1];
								num3 = 0;
								while (num3 < items.Length)
								{
									bill.Items[num3] = items[num3];
									num3++;
								}
							}
							OrderBillItem item = new OrderBillItem();
							item.BillDetailID = (int) row["BillDetailID"];
							item.MenuID = (int) row["MenuID"];
							item.Unit = (int) row["Unit"];
							item.Status = (byte) row["Status"];
							item.Message = (row["Message"] is DBNull) ? null : ((string) row["Message"]);
							item.ServeTime = (row["ServeTime"] is DBNull) ? AppParameter.MinDateTime : ((DateTime) row["ServeTime"]);
							item.CancelReasonID = (int) row["CancelReasonID"];
							item.EmployeeID = (int) row["EmployeeID"];
							item.ChangeFlag = false;
							item.ItemChoices = null;
							bill.Items[bill.Items.Length - 1] = item;
							break;
						}
						num2++;
					}
				}
				table = dataSet.Tables[3];
				if (table.Rows.Count <= 0)
				{
					return information;
				}
				for (num = 0; num < table.Rows.Count; num++)
				{
					row = table.Rows[num];
					int num6 = (int) row["BillDetailID"];
					for (num2 = 0; num2 < information.Bills.Length; num2++)
					{
						if ((information.Bills[num2] != null) && (information.Bills[num2].Items != null))
						{
							for (num3 = 0; num3 < information.Bills[num2].Items.Length; num3++)
							{
								if (information.Bills[num2].Items[num3].BillDetailID == num6)
								{
									OrderBillItem item2 = information.Bills[num2].Items[num3];
									if (item2.ItemChoices == null)
									{
										item2.ItemChoices = new OrderItemChoice[1];
										item2.DefaultOption = false;
									}
									else
									{
										OrderItemChoice[] itemChoices = item2.ItemChoices;
										item2.ItemChoices = new OrderItemChoice[item2.ItemChoices.Length + 1];
										for (int i = 0; i < itemChoices.Length; i++)
										{
											item2.ItemChoices[i] = itemChoices[i];
										}
									}
									OrderItemChoice choice = new OrderItemChoice();
									choice.OptionID = (int) row["OptionID"];
									choice.ChoiceID = (int) row["ChoiceID"];
									item2.ItemChoices[item2.ItemChoices.Length - 1] = choice;
									break;
								}
							}
						}
					}
				}
				information2 = information;
			}
			catch (Exception)
			{
				information2 = null;
			}
			finally
			{
				if (connection != null)
				{
					connection.Close();
				}
			}
			return information2;
		}
Exemplo n.º 3
0
		public string SendOrder(OrderInformation orderInfo, int CustID, string CustFullName)
		{
			return this.SendOrderPrint(orderInfo, CustID, CustFullName, true);
		}