Ejemplo n.º 1
0
        /// <summary>
        /// Add a new entry to the DeliveryDriver table
        /// </summary>
        public static DeliveryDriver Add(int driversEmployeeId, int cashiersEmployeeId,
                                         double amountBankrolled)
        {
            DeliveryDriver result    = null;
            DateTime       startTime = DateTime.Now;

            SqlConnection cn  = GetConnection();
            string        cmd = "AddDeliveryDriver";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@DeliveryDriverEmployeeId", SqlDbType.Int, driversEmployeeId);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverCashierEmployeeId", SqlDbType.Int, cashiersEmployeeId);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverStart", SqlDbType.DateTime, startTime);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverEnd", SqlDbType.DateTime, null);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverAmountBankrolled", SqlDbType.Float, amountBankrolled);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new DeliveryDriver(Convert.ToInt32(sqlCmd.Parameters["@DeliveryDriverId"].Value),
                                                driversEmployeeId, cashiersEmployeeId, amountBankrolled,
                                                startTime, null, null);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update an entry in the DeliveryDriver table
        /// </summary>
        public static bool Update(DeliveryDriver deliveryDriver)
        {
            bool result = false;

            SqlConnection cn = GetConnection();

            result = Update(cn, deliveryDriver);
            FinishedWithConnection(cn);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get an entry from the DeliveryDriver table
        /// </summary>
        public static DeliveryDriver Get(int id)
        {
            DeliveryDriver result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, id);
            FinishedWithConnection(cn);
            return(result);
        }
Ejemplo n.º 4
0
        private static DeliveryDriver Get(SqlConnection cn, int id)
        {
            DeliveryDriver result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM DeliveryDriver WHERE DeliveryDriverId=" + id, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildDeliveryDriver(rdr);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Delete an entry from the DeliveryDriver table
        /// </summary>
        public static bool Delete(int id)
        {
            Int32          rowsAffected   = 0;
            SqlConnection  cn             = GetConnection();
            DeliveryDriver deliveryDriver = Get(cn, id);

            if (deliveryDriver != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM DeliveryDriver WHERE DeliveryDriverId=" + id;
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
Ejemplo n.º 6
0
        private static bool Update(SqlConnection cn, DeliveryDriver deliveryDriver)
        {
            Int32 rowsAffected = 0;

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "UPDATE DeliveryDriver SET DeliveryDriverEmployeeId=@DeliveryDriverEmployeeId,DeliveryDriverCashierEmployeeId=@DeliveryDriverCashierEmployeeId,DeliveryDriverAmountBankrolled=@DeliveryDriverAmountBankrolled,DeliveryDriverStart=@DeliveryDriverStart,DeliveryDriverLastDelivery=@DeliveryDriverLastDelivery,DeliveryDriverEnd=@DeliveryDriverEnd WHERE DeliveryDriverId=@DeliveryDriverId";

                BuildSqlParameter(sqlCmd, "@DeliveryDriverId", SqlDbType.Int, deliveryDriver.Id);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverEmployeeId", SqlDbType.Int, deliveryDriver.DriversEmployeeId);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverCashierEmployeeId", SqlDbType.Int, deliveryDriver.CashiersEmployeeId);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverAmountBankrolled", SqlDbType.Float, deliveryDriver.AmountBankrolled);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverStart", SqlDbType.DateTime, deliveryDriver.StartTime);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverLastDelivery", SqlDbType.DateTime, deliveryDriver.LastDelivery);
                BuildSqlParameter(sqlCmd, "@DeliveryDriverEnd", SqlDbType.DateTime, deliveryDriver.EndTime);

                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            return(rowsAffected != 0);
        }