// Show the quotes of a particular participant public List<QuoteDTO> DTO_BidToShow(int companyID) { //List<Quote> allQuotes = new List<Quote>(); List<QuoteDTO> listQuotesOut = new List<QuoteDTO>(); using (var context = new RFQEntities()) { var allQuotes = (from quote in context.Quotes.Include("QuoteDetails") from participant in context.QuoteParticipants where participant.CompanyID == companyID && quote.CompanyID == participant.CompanyID select new { QuoteID = quote.QuoteID, StartDate = quote.StartDate, EndDate = quote.EndDate, CompanyID = quote.CompanyID, Status = quote.Status } ).ToList(); // if (allQuotes.Count > 0) //{ foreach (var quote in allQuotes) { QuoteDTO quoteRow = new QuoteDTO(); quoteRow.QuoteID = quote.QuoteID; // quoteRow.CompanyID = quote.CompanyID; quoteRow.StartDate = quote.StartDate; quoteRow.EndDate = quote.EndDate; quoteRow.Status = quote.Status; /*foreach (var item in quote.QuoteDetails) { quoteRow.Text = item.Text; quoteRow.Value = item.Value; }*/ listQuotesOut.Add(quoteRow); //} return listQuotesOut; // } // else return null; } } return listQuotesOut; }
public List<QuoteDTO> GetBid() { List<Quote> allQuotes = new List<Quote>(); List<QuoteDTO> listQuotesOut = new List<QuoteDTO>(); using (var context = new RFQEntities()) { allQuotes = (from c in context.Quotes.Include("QuoteDetails") select c).ToList(); } if (allQuotes.Count > 0) { foreach (var quote in allQuotes) { QuoteDTO quoteRow = new QuoteDTO(); quoteRow.QuoteID = quote.QuoteID; quoteRow.CompanyID = quote.CompanyID; quoteRow.StartDate = quote.StartDate; quoteRow.EndDate = quote.EndDate; quoteRow.Status = quote.Status; foreach (var item in quote.QuoteDetails) { quoteRow.Text = item.Text; quoteRow.Value = item.Value; } listQuotesOut.Add(quoteRow); } return listQuotesOut; } else return null; }
//Method that creates new Quotation ****CREATE RFQ BUTTON*** public QuoteAdded CreateNewQuoation(QuoteDTO QuoteNew) { bool check = false; QuoteAdded QuoteValidation = new QuoteAdded(); using (TransactionScope transaction = new TransactionScope()) { try { Quote QuoteIn = new Quote(); //Data transfer to the the AddressIn QuoteIn.StartDate = QuoteNew.StartDate; QuoteIn.EndDate = QuoteNew.EndDate; QuoteIn.Status = 1; using (var context = new RFQEntities()) { //Finding references for the Foreign Keys Company existingCompany = context.Companies.Single(q => q.CompanyID == QuoteNew.CompanyID); //Adding refernces QuoteIn.Company = existingCompany; if (QuoteIn.EntityState == EntityState.Detached) { context.Quotes.AddObject(QuoteIn); } context.SaveChanges(); int id = QuoteIn.QuoteID; QuoteValidation.LastId = id; } } catch (Exception e) { transaction.Dispose(); check = false; QuoteValidation.Added = check; return QuoteValidation; } transaction.Complete(); check = true; QuoteValidation.Added = check; return QuoteValidation; } }
//Method that returns all the active quotes by company ID (the company doesn't participate in these quotes yet // Method is written for SupplierUI public List<QuoteDTO> GetAllActiveQuotes(int companyId) { // IList<Quote> quotes = new List<Quote>(); List<QuoteDTO> quotesToReturn = new List<QuoteDTO>(); using (var context = new RFQEntities()) { var quotes = (from quote in context.Quotes.Include("QuoteDetails") where quote.CompanyID != companyId && quote.Status == 1 select quote).ToList(); if (quotes.Count > 0) { foreach (var quote in quotes) { QuoteDTO quoteToRow = new QuoteDTO() { QuoteID = quote.QuoteID, CompanyID = quote.CompanyID, StartDate = quote.StartDate, EndDate = quote.EndDate, Status = quote.Status }; foreach (var item in quote.QuoteDetails) { quoteToRow.Text = item.Text; quoteToRow.Value = item.Value; } quotesToReturn.Add(quoteToRow); } } } return quotesToReturn; }
public void LoadData() { QuoteDTO quotesToShow = new QuoteDTO(); this.dataGridQuote.DataSource = quotesToShow.GetBid(); dataGridQuote.Columns["CompanyID"].Visible = false; }
private void buttonCreate_Click(object sender, EventArgs e) { try { ApplicationServices appService = new ApplicationServices(); bool emptyText = appService.EmptyTextValidation(this); appService.EmptyTextMark(this); if (!emptyText) throw new EmptyText(); DateTime StartDate = new DateTime(); DateTime EndDate = new DateTime(); string sStartDate = textBoxStartDate.Text; string sEndDate = textBoxEndDate.Text; bool startDateValid = DateTime.TryParse(sStartDate, out StartDate); bool endDateValid = DateTime.TryParse(sEndDate, out EndDate); if (!startDateValid) { textBoxStartDate.BackColor = Color.Red; throw new InvalidDateFormat(); } if (!endDateValid) { textBoxEndDate.BackColor = Color.Red; throw new InvalidDateFormat(); } if (StartDate > EndDate) { throw new DateChronolgy(); } QuoteDTO QuoteIn = new QuoteDTO(); QuoteIn.CompanyID = companyIDIn; QuoteIn.StartDate = StartDate; QuoteIn.EndDate = EndDate; IQuote QuoteFunctions = new QuoteService(); QuoteAdded QuoteValidation = QuoteFunctions.CreateNewQuoation(QuoteIn); if (QuoteValidation.Added == true) { QuoteDetailToCreateDTO DetailToCreate = new QuoteDetailToCreateDTO(); DetailToCreate.QuoteID = QuoteValidation.LastId; DetailToCreate.Text = textBoxDescription.Text; string sValue = textBoxQuantity.Text; decimal dValue; bool isParsed = decimal.TryParse(sValue, out dValue); if (!isParsed) { throw new QuantityWrong(); } DetailToCreate.Value = dValue; bool check = QuoteFunctions.CreateNewQuoteDetail(DetailToCreate); if (check) { MessageBox.Show("Quote was created. ", "app", MessageBoxButtons.OK); this.Close(); instanceMainForm.LoadData(); } else { throw new QuoteFailed(); } } else { throw new QuoteFailed(); } } catch (EmptyText et) { MessageBox.Show("Empty Text, all fields must be filled out.", "app", MessageBoxButtons.OK); } catch (InvalidDateFormat idf) { MessageBox.Show("Date format is invalid. Date format is: 'yyyy/mm/dd' ", "app", MessageBoxButtons.OK); } catch (QuoteFailed qf) { MessageBox.Show("Quote creation failed. Please check your data. ", "app", MessageBoxButtons.OK); } catch (DateChronolgy dc) { MessageBox.Show("Dates are not choronological. ", "app", MessageBoxButtons.OK); } catch(QuantityWrong qw) { MessageBox.Show("Quanity should be decimal. ", "app", MessageBoxButtons.OK); } }
private void btnShowQuotes_Click(object sender, EventArgs e) { createNewBidButtonDisabling(); dgvBidsInfo.DataSource = null; QuoteDTO quotesToShow = new QuoteDTO(); dgvBidsInfo.DataSource = quotesToShow.GetBid(); dgvBidsInfo.Columns["CompanyID"].Visible = false; dgvBidsInfo.Columns["QuoteID"].Visible = false; dgvBidsInfo.Columns["Status"].Visible = false; }