Facebook
From Emerald Water Vole, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 64
  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 Supermarket
  13. {
  14.     public partial class Login : Form
  15.     {
  16.         public static string Sellername = "";
  17.         public Login()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         SqlConnection Con = new SqlConnection(@"[Your Data Location]");
  23.            
  24.         //Login
  25.         private void LoginButton_Click(object sender, EventArgs e)
  26.         {
  27.             if(UsernameTextbox.Text=="" || PasswordTextbox.Text=="")
  28.             {
  29.                 MessageBox.Show("Please enter the Username and Password", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  30.             }
  31.  
  32.             else
  33.             {
  34.                 if(ComboboxRole.SelectedItem.ToString()=="Admin")
  35.                 {
  36.                     //Login Username: Admin Password: Admin
  37.                     if(UsernameTextbox.Text=="Admin" && PasswordTextbox.Text=="Admin")
  38.                     {
  39.                         this.Hide();
  40.                         ProductForm log = new ProductForm();
  41.                         log.Show();
  42.                     }
  43.  
  44.                     else
  45.                     {
  46.                         MessageBox.Show("Username or Password is wrong");
  47.                     }
  48.                 }
  49.  
  50.                 else if(ComboboxRole.SelectedItem.ToString()=="Seller")
  51.                 {
  52.                     Con.Open();
  53.                     SqlDataAdapter sda = new SqlDataAdapter("Select count(8) from SellerData where SellerName='"+UsernameTextbox.Text+ "' and SellerPass='" + PasswordTextbox.Text+"'", Con);
  54.                     DataTable dt = new DataTable();
  55.                     sda.Fill(dt);
  56.  
  57.                     if(dt.Rows[0][0].ToString() == "1")
  58.                     {
  59.                         Sellername = UsernameTextbox.Text;
  60.                         SellingForm log = new SellingForm();
  61.                         log.Show();
  62.                         this.Hide();
  63.                         Con.Close();
  64.                     }
  65.  
  66.                     else
  67.                     {
  68.                         MessageBox.Show("Username or Password Wrong");
  69.                     }
  70.                 }
  71.  
  72.                 else
  73.                 {
  74.                     MessageBox.Show("Please Choose Role First", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }
  80.  
captcha