コード例 #1
0
        public static InvoiceDO RowToItem(DataRow isource)
        {
            //if isource is not null fills in items
            InvoiceDO to = new InvoiceDO();

            to.InvoiceID = (Int64)isource["InvoiceID"];
            if (isource["LastName"] != DBNull.Value)
            {
                to.LastName = isource["LastName"].ToString();
            }
            if (isource["FirstName"] != DBNull.Value)
            {
                to.FirstName = isource["FirstName"].ToString();
            }
            if (isource["Address"] != DBNull.Value)
            {
                to.Address = isource["Address"].ToString();
            }
            if (isource["City"] != DBNull.Value)
            {
                to.City = isource["City"].ToString();
            }
            if (isource["StateProvidence"] != DBNull.Value)
            {
                to.StateProvidence = isource["StateProvidence"].ToString();
            }
            if (isource["Country"] != DBNull.Value)
            {
                to.Country = isource["Country"].ToString();
            }
            if (isource["PostalCode"] != DBNull.Value)
            {
                to.PostalCode = (int)isource["PostalCode"];
            }
            if (isource["DateChartered"] != DBNull.Value)
            {
                to.DateChartered = (DateTime)isource["DateChartered"];
            }
            if (isource["DateReturned"] != DBNull.Value)
            {
                to.DateReturned = (DateTime)isource["DateReturned"];
            }
            if (isource["CostperDay"] != DBNull.Value)
            {
                to.CostperDay = (decimal)isource["CostperDay"];
            }
            if (isource["AmountDue"] != DBNull.Value)
            {
                to.AmountDue = (decimal)isource["AmountDue"];
            }
            if (isource["BoatID"] != DBNull.Value)
            {
                to.BoatID = (Int64)isource["BoatID"];
            }
            if (isource["UserID"] != DBNull.Value)
            {
                to.UserID = (Int64)isource["UserID"];
            }
            return(to);
        }
コード例 #2
0
        public ActionResult UpdateInvoice(InvoicePO form)
        {
            ActionResult oresponse = null;

            try
            {
                if (ModelState.IsValid)
                {
                    //if info is valid returns to view invoices
                    InvoiceDO dataObject = InvoiceMap1.InvoicePOtoDO(form);
                    _invoiceDataAccess.UpdateInvoice(dataObject);
                    oresponse = RedirectToAction("ViewInvoice", "Invoice");
                }
                else
                {
                    //if not returns the form
                    oresponse = View(form);
                }
            }
            catch (Exception ex)
            {
                logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
            }
            finally { }
            return(oresponse);
        }
コード例 #3
0
        public ActionResult UpdateInvoice(Int64 InvoiceID)
        {
            //defines the variables
            InvoiceDO item            = _invoiceDataAccess.ViewInvoiceByID(InvoiceID);
            InvoicePO invoiceToUpdate = InvoiceMap1.InvoiceDOtoInvoicePO(item);

            return(View(invoiceToUpdate));
        }
コード例 #4
0
        public void UpdateInvoice(InvoiceDO invoice)
        {
            //defines variables
            SqlConnection connection = null;
            SqlCommand    updateInvoiceRowCommand = null;

            try
            {
                //gets connection then defines the parameters to be entered
                connection = new SqlConnection(_ConnectionString);
                updateInvoiceRowCommand             = new SqlCommand("UPDATE_INVOICE", connection);
                updateInvoiceRowCommand.CommandType = CommandType.StoredProcedure;
                connection.Open();
                updateInvoiceRowCommand.Parameters.AddWithValue("InvoiceID", invoice.InvoiceID);
                updateInvoiceRowCommand.Parameters.AddWithValue("LastName", invoice.LastName);
                updateInvoiceRowCommand.Parameters.AddWithValue("FirstName", invoice.FirstName);
                updateInvoiceRowCommand.Parameters.AddWithValue("Address", invoice.Address);
                updateInvoiceRowCommand.Parameters.AddWithValue("City", invoice.City);
                updateInvoiceRowCommand.Parameters.AddWithValue("StateProvidence", invoice.StateProvidence);
                updateInvoiceRowCommand.Parameters.AddWithValue("Country", invoice.Country);
                updateInvoiceRowCommand.Parameters.AddWithValue("PostalCode", invoice.PostalCode);
                updateInvoiceRowCommand.Parameters.AddWithValue("DateChartered", invoice.DateChartered);
                updateInvoiceRowCommand.Parameters.AddWithValue("DateReturned", invoice.DateReturned);
                updateInvoiceRowCommand.Parameters.AddWithValue("CostperDay", invoice.CostperDay);
                updateInvoiceRowCommand.Parameters.AddWithValue("AmountDue", invoice.AmountDue);
                updateInvoiceRowCommand.Parameters.AddWithValue("BoatID", invoice.BoatID);
                updateInvoiceRowCommand.Parameters.AddWithValue("UserID", invoice.UserID);
                updateInvoiceRowCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                throw ex;
            }
            finally
            {
                //if null close and dispose
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }
        }
コード例 #5
0
        public static InvoiceBO InvoiceDOtoInvoiceBO(InvoiceDO from)
        {
            //maps to and from do to po
            InvoiceBO to = new InvoiceBO();

            to.InvoiceID       = from.InvoiceID;
            to.LastName        = from.LastName;
            to.FirstName       = from.FirstName;
            to.Address         = from.Address;
            to.City            = from.City;
            to.StateProvidence = from.StateProvidence;
            to.Country         = from.Country;
            to.PostalCode      = from.PostalCode;
            to.DateChartered   = from.DateChartered;
            to.DateReturned    = from.DateReturned;
            to.CostperDay      = from.CostperDay;
            to.AmountDue       = from.AmountDue;
            to.BoatID          = from.BoatID;
            to.UserID          = from.UserID;
            return(to);
        }
コード例 #6
0
        public ActionResult AddInvoice(InvoicePO form)
        {
            ActionResult oResponse = null;

            try
            {
                if (ModelState.IsValid)
                {
                    //defines variables for boat .. and double days
                    BoatDO boat = _boatDataAccess.ViewBoatByID(form.BoatID);
                    double days = form.DateReturned.Subtract(form.DateChartered).TotalDays;
                    //if greater than 0
                    if (days > 0)
                    {
                        //amount due = cost x days
                        form.AmountDue  = boat.CostperDay * (decimal)days;
                        form.CostperDay = boat.CostperDay;
                        InvoiceDO dataObject = InvoiceMap1.InvoicePOtoDO(form);
                        _invoiceDataAccess.AddInvoice(dataObject);
                        oResponse = RedirectToAction("ViewInvoice", "Invoice");
                    }
                    else
                    {
                        TempData["ErrorMsg"] = "Date Returned can not be less than Date Chartered.";
                        //TODO: fill select items
                        oResponse = View(form);
                    }
                }
                else
                {
                    oResponse = View(form);
                }
            }
            catch (Exception ex)
            {
                logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
            }
            finally { }
            return(oResponse);
        }
コード例 #7
0
        public InvoiceDO ViewInvoiceByID(Int64 InvoiceID)
        {
            //get list
            InvoiceDO invoice = new InvoiceDO();
            //defines variables
            SqlConnection  connection = null;
            SqlDataAdapter adapter    = null;
            DataTable      table      = new DataTable();
            SqlCommand     command    = null;

            try
            {
                //gets connection to database
                connection          = new SqlConnection(_ConnectionString);
                command             = new SqlCommand("VIEW_INVOICE_BY_ID", connection);
                command.CommandType = CommandType.StoredProcedure;
                connection.Open();
                command.Parameters.AddWithValue("@InvoiceID", InvoiceID);
                adapter = new SqlDataAdapter(command);
                adapter.Fill(table);
                invoice = InvoiceMap2.DataTableToList(table).FirstOrDefault();
            }
            catch (Exception ex)
            {
                logger.Log("Fatal", ex.Source, ex.TargetSite.ToString(), ex.Message, ex.StackTrace);
                throw ex;
            }
            finally
            {
                //if not null close and dispose
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }
            return(invoice);
        }