Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. SELECT AnalysisItems.ProductName,
  2. BeginningCount.CountNumber AS Beginning,
  3. sum(Transactions.TransactionQty) AS SumOfTransactionQty,
  4. EndingCount.CountNumber AS Ending
  5. FROM Product
  6. INNER JOIN (((AnalysisItems
  7. INNER JOIN BeginningCount ON AnalysisItems.Pmid = BeginningCount.Pmid)
  8. INNER JOIN EndingCount ON BeginningCount.Pmid = EndingCount.Pmid)
  9. INNER JOIN Transactions ON EndingCount.Pmid = Transactions.Pmid)
  10. ON (AnalysisItems.Pmid = Product.Pmid) AND (Product.Pmid = Transactions.Pmid)
  11. WHERE (((Product.ProductAnalysis)=1))
  12. GROUP BY AnalysisItems.ProductName, BeginningCount.CountNumber,
  13. EndingCount.CountNumber;
  14.  
  15. SELECT
  16. AnalysisItems.ProductName,
  17. BeginningCount.CountNumber AS Beginning,
  18. Sum(Transactions.TransactionQty) AS SumOfTransactionQty,
  19. EndingCount.CountNumber AS Ending,
  20. EndingCount.StoreAccount
  21. FROM Product
  22. INNER JOIN
  23. (
  24. AnalysisItems
  25. INNER JOIN BeginningCount ON
  26. AnalysisItems.Pmid = BeginningCount.Pmid
  27. INNER JOIN EndingCount ON
  28. BeginningCount.Pmid = EndingCount.Pmid
  29. INNER JOIN Transactions ON
  30. EndingCount.Pmid = Transactions.Pmid
  31. ) ON
  32. (Product.Pmid = AnalysisItems.Pmid) AND
  33. (Product.Pmid = Transactions.Pmid)
  34. WHERE (((Product.ProductAnalysis)=1))
  35. GROUP BY
  36. AnalysisItems.ProductName,
  37. BeginningCount.CountNumber,
  38. EndingCount.CountNumber,
  39. EndingCount.StoreAccount;
  40.  
  41. private void btnLoad_Click(object sender, EventArgs e)
  42. {
  43.  
  44. //to load the first chosen months data
  45. this.beginningCountTableAdapter.Fill(this.beginningDataSet.BeginningCount, Convert.ToInt32(storeAccountComboBox.Text), Convert.ToDateTime(dateTimePicker1.Text));
  46. //to load the second chosen months data
  47. this.endingCountTableAdapter.Fill(this.endingDataSet.EndingCount, Convert.ToInt32(storeAccountComboBox.Text), Convert.ToDateTime(dateTimePicker2.Text));
  48.  
  49. //Create new DataTable
  50. DataTable dtItems = new DataTable();
  51.  
  52. //add columns to the dataTable
  53. dtItems.Columns.Add("Product", typeof(string));
  54. dtItems.Columns.Add("Beginning", typeof(decimal));
  55. dtItems.Columns.Add("Purchases", typeof(int));
  56. dtItems.Columns.Add("Ending", typeof(decimal));
  57. //Add a new Column to Calculate the Value
  58. dtItems.Columns.Add("Total Gone (Usage)", typeof(decimal));
  59. //add more columns for $ value
  60. dtItems.Columns.Add("Beginning$", typeof(decimal));
  61. dtItems.Columns.Add("Purchases$", typeof(decimal));
  62. dtItems.Columns.Add("Ending$", typeof(decimal));
  63. //Add a new Column to Calculate the Value
  64. dtItems.Columns.Add("Total Gone ($)", typeof(decimal));
  65. dtItems.Columns.Add("% of Sales", typeof(decimal));
  66.  
  67. try
  68. {
  69. for (int i = 0; i < dataGridView1.RowCount; i++)
  70. {
  71. //first column
  72. string product = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
  73.  
  74. //calculation for TotalGone (usage)
  75. decimal beginning = Convert.ToDecimal(dataGridView1.Rows[i].Cells[1].Value);
  76. decimal purchases = Convert.ToDecimal(dataGridView2.Rows[i].Cells[0].Value);
  77. decimal ending = Convert.ToDecimal(dataGridView2.Rows[i].Cells[1].Value);
  78. decimal totalGone = ((beginning + purchases) - ending);
  79. //Variables for conversions for $ column math
  80. decimal beg = Convert.ToDecimal(dataGridView1.Rows[i].Cells[1].Value);
  81. decimal begPrice = Convert.ToDecimal(dataGridView1.Rows[i].Cells[2].Value);
  82. decimal begValue = beg * begPrice;
  83. decimal pur = Convert.ToDecimal(dataGridView2.Rows[i].Cells[0].Value);
  84. decimal purPrice = Convert.ToDecimal(dataGridView2.Rows[i].Cells[2].Value);
  85. decimal purValue = pur * purPrice;
  86. decimal end = Convert.ToDecimal(dataGridView2.Rows[i].Cells[1].Value);
  87. decimal endPrice = Convert.ToDecimal(dataGridView2.Rows[i].Cells[2].Value);
  88. decimal endValue = end * endPrice;
  89. decimal totalGoneValue = ((beg * begPrice) + (pur * purPrice)) - (end * endPrice);
  90.  
  91. totalGoneColumnTotal = totalGoneColumnTotal + totalGoneValue; //The total of all product totalGoneValues
  92. decimal salesPercentage = 0; //The sales percentage
  93. thirtyPercent = Convert.ToDecimal(txtThirtyPct.Text); //the thirty percent discount txt entry
  94. double chickenValue = Convert.ToDouble(dataGridView2.Rows[28].Cells[0].Value);
  95. chickenRebate = (chickenValue * .512);
  96. double steakValue = Convert.ToDouble(dataGridView2.Rows[29].Cells[0].Value);
  97. steakRebate = steakValue * .550;
  98. totalWithRebates = (Convert.ToDouble(totalWithDiscount) - ((chickenRebate + steakRebate)));
  99. try
  100. {
  101. decimal sales = Convert.ToDecimal(textSales.Text); //convert the sales entry
  102. salesPercentage = totalGoneValue / sales * 100; //find sales percentage
  103. totalWithDiscount = totalGoneColumnTotal - thirtyPercent; //find thirtypercent discount amount
  104. }
  105. catch { MessageBox.Show("The sales entry must be a number between 1 and 999999.99");
  106. break;
  107. }
  108.  
  109. //add colors to the output.
  110.  
  111.  
  112. //Add rows to the DataTable
  113. dtItems.Rows.Add(product, beginning, purchases, ending, totalGone, begValue, purValue, endValue, totalGoneValue, salesPercentage);
  114. }//end for
  115.  
  116. //Totals Summary Rows
  117. dtItems.Rows.Add("Totals", null, null, null, null, null, null, null, totalGoneColumnTotal, null);
  118. dtItems.Rows.Add("30% discounts", null, null, null, null, null, null, null, thirtyPercent ,null);
  119. dtItems.Rows.Add("Total w/discount", null, null, null, null, null, null, null, totalWithDiscount, null);
  120. dtItems.Rows.Add("Chicken Rebate x * 5.12", null, null, null, null, null, null, null, chickenRebate, null);
  121. dtItems.Rows.Add("Steak Rebate x * 5.50", null, null, null, null, null, null, null, steakRebate, null);
  122. dtItems.Rows.Add("Total w/Rebates", null, null, null, null, null, null, null, totalWithRebates, null);
  123.  
  124. //Set the DataTable as DataSource of the GridView
  125. dataGridView3.DataSource = dtItems;
  126. }
  127. catch { MessageBox.Show("Could not determine values. There may be no data for this date range/store."); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement