Guest User

Report Form PBKK

a guest
May 9th, 2021
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace SupermarketManagementSystem
  13. {
  14.     public partial class ReportForm : Form
  15.     {
  16.         public ReportForm()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         SqlConnection Con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\aldo\source\repos\PointOfSale\SupermarketManagementSystem\smarketdb.mdf;Integrated Security=True;Connect Timeout=30");
  22.  
  23.         private void populateIncome()
  24.         {
  25.             Con.Open();
  26.             string query = "select * from BillTbl";
  27.             SqlDataAdapter sda = new SqlDataAdapter(query, Con);
  28.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  29.             var ds = new DataSet();
  30.             sda.Fill(ds);
  31.             IncomeDGV.DataSource = ds.Tables[0];
  32.             Con.Close();
  33.         }
  34.  
  35.         private void populateOutcome()
  36.         {
  37.             Con.Open();
  38.             string query = "select * from OutcomeTbl";
  39.             SqlDataAdapter sda = new SqlDataAdapter(query, Con);
  40.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  41.             var ds = new DataSet();
  42.             sda.Fill(ds);
  43.             OutcomeDGV.DataSource = ds.Tables[0];
  44.             Con.Close();
  45.         }
  46.  
  47.         private void totalIncome()
  48.         {
  49.             Con.Open();
  50.             string query = "select SUM(TotAmt) from BillTbl";
  51.             SqlDataAdapter sda = new SqlDataAdapter(query, Con);
  52.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  53.             var ds = new DataSet();
  54.             sda.Fill(ds);
  55.             if (ds.Tables[0].Rows[0][0].ToString().Equals("")) TotIncome.Text = "0";
  56.             else TotIncome.Text = ds.Tables[0].Rows[0][0].ToString();
  57.             Con.Close();
  58.         }
  59.  
  60.         private void totalOutcome()
  61.         {
  62.             Con.Open();
  63.             string query = "select SUM(OutTotal) from OutcomeTbl";
  64.             SqlDataAdapter sda = new SqlDataAdapter(query, Con);
  65.             SqlCommandBuilder builder = new SqlCommandBuilder(sda);
  66.             var ds = new DataSet();
  67.             sda.Fill(ds);
  68.             if (ds.Tables[0].Rows[0][0].ToString().Equals("")) TotOutcome.Text = "0";
  69.             else TotOutcome.Text = ds.Tables[0].Rows[0][0].ToString();
  70.             Con.Close();
  71.         }
  72.  
  73.         private void totalFinal()
  74.         {
  75.             int income = Convert.ToInt32(TotIncome.Text);
  76.             int outcome = Convert.ToInt32(TotOutcome.Text);
  77.             int total;
  78.             if(income > outcome)
  79.             {
  80.                 total = income - outcome;
  81.                 TotAmt.Text = total.ToString();
  82.                 TotDesc.Text = "Profit Rp";
  83.             }
  84.             else if(income < outcome)
  85.             {
  86.                 total = outcome - income;
  87.                 TotAmt.Text = total.ToString();
  88.                 TotDesc.Text = "Loss Rp";
  89.             }
  90.             else
  91.             {
  92.                 total = 0;
  93.                 TotAmt.Text = total.ToString();
  94.                 TotDesc.Text = "Profit/Loss Rp";
  95.             }
  96.         }
  97.  
  98.         private void ReportForm_Load(object sender, EventArgs e)
  99.         {
  100.             populateIncome();
  101.             populateOutcome();
  102.             totalIncome();
  103.             totalOutcome();
  104.             totalFinal();
  105.         }
  106.  
  107.         private void button3_Click(object sender, EventArgs e)
  108.         {
  109.             ProductForm prod = new ProductForm();
  110.             prod.Show();
  111.             this.Hide();
  112.         }
  113.  
  114.         private void button2_Click(object sender, EventArgs e)
  115.         {
  116.             CategoryForm cat = new CategoryForm();
  117.             cat.Show();
  118.             this.Hide();
  119.         }
  120.  
  121.         private void button1_Click(object sender, EventArgs e)
  122.         {
  123.             SellerForm cat = new SellerForm();
  124.             cat.Show();
  125.             this.Hide();
  126.         }
  127.  
  128.         private void button5_Click(object sender, EventArgs e)
  129.         {
  130.             IncomeForm inc = new IncomeForm();
  131.             inc.Show();
  132.             this.Hide();
  133.         }
  134.  
  135.         private void button9_Click(object sender, EventArgs e)
  136.         {
  137.             OutcomeForm outc = new OutcomeForm();
  138.             outc.Show();
  139.             this.Hide();
  140.         }
  141.  
  142.         private void label7_Click(object sender, EventArgs e)
  143.         {
  144.             this.Hide();
  145.             Form1 login = new Form1();
  146.             login.Show();
  147.         }
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment