private void frmMain_Load(object sender, EventArgs e)
        {
            con = new SqlConnection(cs.DBConn);
            string inv = "select count(*) from DbNewSales";

            cmd = new SqlCommand(inv, con);

            con.Open();
            cmd.ExecuteNonQuery();

            rdr = cmd.ExecuteReader(0);

            while (rdr.Read())
            {
                int n = rdr.GetInt32(0);
                lblSonum.Text = "" + n.ToString();
            }
            con.Close();

            string qwe = "select count(*) from DbNewSupplier";

            cmd = new SqlCommand(qwe, con);

            con.Open();
            cmd.ExecuteNonQuery();

            rdr = cmd.ExecuteReader(0);

            while (rdr.Read())
            {
                int n = rdr.GetInt32(0);
                lblPonum.Text = "" + n.ToString();
            }
            con.Close();

            string zxc = "select count(*) from Dbinventory where (Quantity <= ReorderPoint)";

            cmd = new SqlCommand(zxc, con);

            con.Open();
            cmd.ExecuteNonQuery();

            rdr = cmd.ExecuteReader(0);

            while (rdr.Read())
            {
                int n = rdr.GetInt32(0);
                lblPrno.Text = "" + n.ToString();
            }
            con.Close();

            con            = new SqlConnection(cs.DBConn);
            cmd            = new SqlCommand();
            cmd.Connection = con;
            string query = "select ProductName,Quantity,ReorderPoint from Dbinventory where(Quantity <= ReorderPoint)";

            cmd.CommandText = query;
            da = new SqlDataAdapter(cmd);
            dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;

            if (lblUserType.Text == "Inventory Manager")
            {
                frmMain       main       = new frmMain();
                frmInventory  inventory  = new frmInventory();
                frmSales      sales      = new frmSales();
                frmPurchase   purchase   = new frmPurchase();
                frmMonitoring monitoring = new frmMonitoring();
                frmReports    reports    = new frmReports();

                main.btnSales.Enabled      = false;
                main.btnPurchasing.Enabled = false;

                inventory.btnSales.Enabled      = false;
                inventory.btnPurchasing.Enabled = false;

                sales.btnSales.Enabled          = false;
                sales.btnPurchasing.Enabled     = false;
                sales.lblCustomerList.Enabled   = false;
                sales.lblNewCustomer.Enabled    = false;
                sales.lblNewSalesOrder.Enabled  = false;
                sales.lblSalesOrderList.Enabled = false;

                purchase.btnSales.Enabled             = false;
                purchase.btnPurchasing.Enabled        = false;
                purchase.lblNewPurchaseOrder.Enabled  = false;
                purchase.lblNewSupplier.Enabled       = false;
                purchase.lblPurchaseOrderList.Enabled = false;
                purchase.lblSupplierList.Enabled      = false;

                monitoring.btnSales.Enabled     = false;
                monitoring.btnPuchasing.Enabled = false;

                reports.btnPurchasing.Enabled = false;
                reports.btnSales.Enabled      = false;
            }
            else if (lblUserType.Text == "Sales Manager")
            {
                frmMain       main       = new frmMain();
                frmInventory  inventory  = new frmInventory();
                frmSales      sales      = new frmSales();
                frmPurchase   purchase   = new frmPurchase();
                frmMonitoring monitoring = new frmMonitoring();
                frmReports    reports    = new frmReports();

                main.btnInventory.Enabled = false;

                inventory.btnInventory.Enabled = false;
                inventory.label5.Enabled       = false;
                inventory.label6.Enabled       = false;

                sales.btnInventory.Enabled = false;

                purchase.btnInventory.Enabled = false;

                monitoring.btnInventory.Enabled = false;

                reports.btnInventory.Enabled = false;
            }
        }
        private void frmInventory_Load(object sender, EventArgs e)
        {
            if (lblUserType.Text == "Inventory Manager")
            {
                frmMain       main       = new frmMain();
                frmInventory  inventory  = new frmInventory();
                frmSales      sales      = new frmSales();
                frmPurchase   purchase   = new frmPurchase();
                frmMonitoring monitoring = new frmMonitoring();
                frmReports    reports    = new frmReports();

                main.btnSales.Enabled      = false;
                main.btnPurchasing.Enabled = false;

                inventory.btnSales.Enabled      = false;
                inventory.btnPurchasing.Enabled = false;

                sales.btnSales.Enabled          = false;
                sales.btnPurchasing.Enabled     = false;
                sales.lblCustomerList.Enabled   = false;
                sales.lblNewCustomer.Enabled    = false;
                sales.lblNewSalesOrder.Enabled  = false;
                sales.lblSalesOrderList.Enabled = false;

                purchase.btnSales.Enabled             = false;
                purchase.btnPurchasing.Enabled        = false;
                purchase.lblNewPurchaseOrder.Enabled  = false;
                purchase.lblNewSupplier.Enabled       = false;
                purchase.lblPurchaseOrderList.Enabled = false;
                purchase.lblSupplierList.Enabled      = false;

                monitoring.btnSales.Enabled     = false;
                monitoring.btnPuchasing.Enabled = false;

                reports.btnPurchasing.Enabled = false;
                reports.btnSales.Enabled      = false;
            }
            else if (lblUserType.Text == "Sales Manager")
            {
                frmMain       main       = new frmMain();
                frmInventory  inventory  = new frmInventory();
                frmSales      sales      = new frmSales();
                frmPurchase   purchase   = new frmPurchase();
                frmMonitoring monitoring = new frmMonitoring();
                frmReports    reports    = new frmReports();

                main.btnInventory.Enabled = false;

                inventory.btnInventory.Enabled = false;
                inventory.label5.Enabled       = false;
                inventory.label6.Enabled       = false;

                sales.btnInventory.Enabled = false;

                purchase.btnInventory.Enabled = false;

                monitoring.btnInventory.Enabled = false;

                reports.btnInventory.Enabled = false;
            }

            con            = new SqlConnection(cs.DBConn);
            cmd            = new SqlCommand();
            cmd.Connection = con;
            string cb = "select top 5 ProductName, sum(Quantity) as QuantitySold from DbNewSales group by ProductName order by QuantitySold desc";

            cmd.CommandText = cb;
            da = new SqlDataAdapter(cmd);
            dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;

            cmd            = new SqlCommand();
            cmd.Connection = con;
            string query = "Select ProductCode,ProductName,BrandName,Category,Datetime from DbInventory Order by DateTime DESC";

            cmd.CommandText = query;
            da = new SqlDataAdapter(cmd);
            dt = new DataTable();
            da.Fill(dt);
            dataGridView2.DataSource = dt;

            cmd = new SqlCommand("select top(5) * from Dbinventory order by Quantity Desc", con);
            con.Open();
            rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                //this.chart1.Series["AvailableQty"].Points.AddXY(rdr.GetString("ProductName"), rdr.GetInt32("AvailableQty"));

                chart1.DataSource = rdr;

                this.chart1.Series[0].XValueMember  = "ProductName";
                this.chart1.Series[0].YValueMembers = "Quantity";

                chart1.DataBind();
            }
        }
示例#3
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            /*con = new SqlConnection(cs.DBConn);
             * con.Open();
             * cmd = new SqlCommand("Select * from DbLogin where UserName='******' and Password = '******'");
             * cmd.Connection = con;
             * rdr = cmd.ExecuteReader();
             *
             * int count = 0;
             *
             * while (rdr.Read())
             * {
             *  count += 1;
             * }
             *
             * if (count == 1)
             * {
             *  MessageBox.Show("Succesfully Login", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             *
             * this.Hide();
             * frmMain main = new frmMain();
             * main.Show();
             * main.label1.Text = txtUserName.Text;
             * }
             * else if (txtUserName.Text == "" || txtPassword.Text == "")
             * {
             *  MessageBox.Show("Please fill-up all the required field/s", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }
             *
             * else
             * {
             *  MessageBox.Show("Invalid Username or Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *  txtUserName.Text = null;
             *  txtPassword.Text = null;
             * }*/



            if (txtUserName.Text == "")
            {
                MessageBox.Show("Please enter UserName", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserName.Focus();
                return;
            }
            if (txtPassword.Text == "")
            {
                MessageBox.Show("Please enter Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPassword.Focus();
                return;
            }
            //try
            //{
            con = new SqlConnection(cs.DBConn);
            cmd = new SqlCommand("SELECT UserName,Password FROM DbLogin WHERE UserName = @UserName AND Password = @Password", con);
            SqlParameter UserName = new SqlParameter("@UserName", SqlDbType.VarChar);
            SqlParameter Password = new SqlParameter("@Password", SqlDbType.VarChar);

            UserName.Value = txtUserName.Text;
            Password.Value = txtPassword.Text;
            cmd.Parameters.Add(UserName);
            cmd.Parameters.Add(Password);
            cmd.Connection.Open();
            SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            if (myReader.Read() == true)
            {
                con = new SqlConnection(cs.DBConn);
                con.Open();
                string ct = "select UserType from DbLogin where UserName='******' and Password='******'";
                cmd            = new SqlCommand(ct);
                cmd.Connection = con;
                rdr            = cmd.ExecuteReader();
                if (rdr.Read())
                {
                    lblAdmin.Text     = (rdr.GetString(0));
                    lblInventory.Text = (rdr.GetString(0));
                    lblSales.Text     = (rdr.GetString(0));
                }
                if ((rdr != null))
                {
                    rdr.Close();
                }

                if (lblAdmin.Text.Trim() == "Admin")
                {
                    con = new SqlConnection(cs.DBConn);
                    con.Open();
                    string aa = "insert into DbUserLogs(UserName,UserType,DateTime,Activity) VALUES ('" + txtUserName.Text + "','" + lblAdmin.Text + "','" + lblDateTime.Text + "','" + label2.Text + "')";
                    cmd            = new SqlCommand(aa);
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();


                    this.Hide();
                    frmMain main = new frmMain();
                    main.Show();
                    main.lblUserName.Text = txtUserName.Text;
                    main.lblUserType.Text = lblAdmin.Text;
                }
                if (lblInventory.Text.Trim() == "Inventory Manager")
                {
                    con = new SqlConnection(cs.DBConn);
                    con.Open();
                    string aa = "insert into DbUserLogs(UserName,UserType,DateTime,Activity) VALUES ('" + txtUserName.Text + "','" + lblAdmin.Text + "','" + lblDateTime.Text + "','" + label2.Text + "')";
                    cmd            = new SqlCommand(aa);
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();

                    this.Hide();
                    frmMain main = new frmMain();

                    main.lblUserName.Text = txtUserName.Text;
                    main.lblUserType.Text = lblInventory.Text;

                    main.btnSales.Enabled      = false;
                    main.btnPurchasing.Enabled = false;

                    frmInventory inventory = new frmInventory();
                    inventory.btnSales.Enabled      = false;
                    inventory.btnPurchasing.Enabled = false;

                    frmSales sales = new frmSales();
                    sales.btnSales.Enabled          = false;
                    sales.btnPurchasing.Enabled     = false;
                    sales.lblCustomerList.Enabled   = false;
                    sales.lblNewCustomer.Enabled    = false;
                    sales.lblNewSalesOrder.Enabled  = false;
                    sales.lblSalesOrderList.Enabled = false;


                    frmPurchase purchase = new frmPurchase();
                    purchase.btnSales.Enabled             = false;
                    purchase.btnPurchasing.Enabled        = false;
                    purchase.lblNewPurchaseOrder.Enabled  = false;
                    purchase.lblNewSupplier.Enabled       = false;
                    purchase.lblPurchaseOrderList.Enabled = false;
                    purchase.lblSupplierList.Enabled      = false;

                    frmMonitoring monitoring = new frmMonitoring();
                    monitoring.btnSales.Enabled     = false;
                    monitoring.btnPuchasing.Enabled = false;

                    frmReports reports = new frmReports();
                    reports.btnPurchasing.Enabled = false;
                    reports.btnSales.Enabled      = false;

                    main.Show();
                }
                if (lblSales.Text.Trim() == "Sales Manager")
                {
                    con = new SqlConnection(cs.DBConn);
                    con.Open();
                    string aa = "insert into DbUserLogs(UserName,UserType,DateTime,Activity) VALUES ('" + txtUserName.Text + "','" + lblAdmin.Text + "','" + lblDateTime.Text + "','" + label2.Text + "')";
                    cmd            = new SqlCommand(aa);
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();

                    this.Hide();
                    frmMain main = new frmMain();
                    main.Show();
                    main.lblUserName.Text = txtUserName.Text;
                    main.lblUserType.Text = lblSales.Text;

                    main.btnInventory.Enabled = false;

                    frmInventory inventory = new frmInventory();
                    inventory.btnInventory.Enabled = false;
                    inventory.label5.Enabled       = false;
                    inventory.label6.Enabled       = false;

                    frmSales sales = new frmSales();
                    sales.btnInventory.Enabled = false;

                    frmPurchase purchase = new frmPurchase();
                    purchase.btnInventory.Enabled = false;

                    frmMonitoring monitoring = new frmMonitoring();
                    monitoring.btnInventory.Enabled = false;

                    frmReports reports = new frmReports();
                    reports.btnInventory.Enabled = false;
                }
            }
            else
            {
                MessageBox.Show("Login is Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);

                txtUserName.Clear();
                txtPassword.Clear();
                txtUserName.Focus();
            }
            if (con.State == ConnectionState.Open)
            {
                con.Dispose();
            }

            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
        }