public static string CustomerInsert(CustomerInformation custInfo) { try { SqlConnection connection = ConnectDB.GetConnection(); SqlCommand command = new SqlCommand("insertCustomer", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@firstName", SqlDbType.NVarChar).Value = custInfo.FirstName; command.Parameters.Add("@middleName", SqlDbType.NVarChar).Value = custInfo.MiddleName; command.Parameters.Add("@lastName", SqlDbType.NVarChar).Value = custInfo.LastName; command.Parameters.Add("@telephone", SqlDbType.VarChar).Value = custInfo.Telephone; command.Parameters.Add("@address", SqlDbType.NVarChar).Value = custInfo.Address; command.Parameters.Add("@description", SqlDbType.NVarChar).Value = custInfo.Description; SqlParameter parameter7 = command.Parameters.Add("@roadid", SqlDbType.Int); if (custInfo.RoadID > 0) { parameter7.Value = custInfo.RoadID; } else { parameter7.Value = DBNull.Value; } SqlParameter parameter8 = command.Parameters.Add("@otherroadname", SqlDbType.NVarChar); if (custInfo.OtherRoadName != null) { parameter8.Value = custInfo.OtherRoadName; } else { parameter8.Value = DBNull.Value; } SqlParameter parameter9 = command.Parameters.Add("@result", SqlDbType.Int); parameter9.Direction = ParameterDirection.Output; command.ExecuteNonQuery(); connection.Close(); parameter9.Value.ToString(); return null; } catch (Exception exception) { return exception.Message.ToString(); } }
public CustomerInformation[] SearchCustomers(string telephone, string fname, string mname, string lname) { try { SqlConnection connection = ConnectDB.GetConnection(); SqlCommand selectCommand = new SqlCommand("getCustomerInformation", connection); selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.Parameters.Add("@tel", SqlDbType.VarChar).Value = telephone; selectCommand.Parameters.Add("@fname", SqlDbType.NVarChar).Value = fname; selectCommand.Parameters.Add("@mname", SqlDbType.NVarChar).Value = mname; selectCommand.Parameters.Add("@lname", SqlDbType.NVarChar).Value = lname; SqlDataAdapter adapter = new SqlDataAdapter(selectCommand); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); connection.Close(); if (dataTable.Rows.Count <= 0) { return null; } CustomerInformation[] informationArray = new CustomerInformation[dataTable.Rows.Count]; for (int i = 0; i < dataTable.Rows.Count; i++) { int custID = (int) dataTable.Rows[i]["CustID"]; string firstName = dataTable.Rows[i]["CustFirstName"].ToString(); string middleName = dataTable.Rows[i]["CustMiddleName"].ToString(); string lastName = dataTable.Rows[i]["CustLastName"].ToString(); string str4 = dataTable.Rows[i]["CustTel"].ToString(); string address = dataTable.Rows[i]["CustAddress"].ToString(); string description = dataTable.Rows[i]["CustDescription"].ToString(); int roadID = (dataTable.Rows[i]["RoadID"] is DBNull) ? 0 : ((int) dataTable.Rows[i]["RoadID"]); string otherRoadName = (dataTable.Rows[i]["OtherRoadName"] is DBNull) ? null : dataTable.Rows[i]["OtherRoadName"].ToString(); informationArray[i] = new CustomerInformation(custID, firstName, middleName, lastName, str4, address, description, roadID, otherRoadName); } return informationArray; } catch (Exception) { return null; } }
public string SetCustomer(CustomerInformation custInfo) { if (custInfo.CustID == 0) { return CustomerInformation.CustomerInsert(custInfo); } return CustomerInformation.CustomerUpdate(custInfo); }
public TakeOutInformation(int orderID, DateTime orderDate, CustomerInformation custInfo) { this.OrderID = orderID; this.OrderDate = orderDate; this.CustInfo = custInfo; }
public TakeOutInformation() { this.OrderID = 0; this.OrderDate = DateTime.MinValue; this.CustInfo = null; }
public TakeOutInformation[] GetTakeOutList() { try { SqlConnection connection = ConnectDB.GetConnection(); SqlCommand selectCommand = new SqlCommand("getTakeOutList", connection); selectCommand.CommandType = CommandType.StoredProcedure; SqlDataAdapter adapter = new SqlDataAdapter(selectCommand); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); connection.Close(); if (dataTable.Rows.Count <= 0) { return null; } TakeOutInformation[] informationArray = new TakeOutInformation[dataTable.Rows.Count]; for (int i = 0; i < dataTable.Rows.Count; i++) { int orderID = (int) dataTable.Rows[i]["orderID"]; DateTime orderDate = (dataTable.Rows[i]["createdate"] is DBNull) ? AppParameter.MinDateTime : ((DateTime) dataTable.Rows[i]["createdate"]); CustomerInformation custInfo = new CustomerInformation(); custInfo.CustID = (int) dataTable.Rows[i]["CustID"]; custInfo.FirstName = dataTable.Rows[i]["CustFirstName"].ToString(); custInfo.MiddleName = dataTable.Rows[i]["CustMiddleName"].ToString(); custInfo.LastName = dataTable.Rows[i]["CustLastName"].ToString(); custInfo.Telephone = dataTable.Rows[i]["CustTel"].ToString(); custInfo.Address = dataTable.Rows[i]["CustAddress"].ToString(); custInfo.Description = dataTable.Rows[i]["CustDescription"].ToString(); informationArray[i] = new TakeOutInformation(orderID, orderDate, custInfo); } return informationArray; } catch (Exception) { return null; } }