Ejemplo n.º 1
0
        private void updateHourIsPaid(String isPaid)
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand("update tblEmployeeHours set isPaid = " + isPaid +
                                                " where EventID = (select EventId from tblEvent" +
                                                " where EventDate between '" + dtpFormDate.Value.Date.ToShortDateString() +
                                                "' and  '" + dtpToDate.Value.Date.ToShortDateString() + "'); ", dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value


            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                // MessageBox.Show("del->" + ex.Message);
            }
            finally
            {
                dbConnection.Close();
            }
        }
Ejemplo n.º 2
0
      private void DelExpenses(string expId)
      {
          SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

          // Create new SQL command
          SqlCommand command = new SqlCommand("Delete from [tblMiscellaneousExpense] where " +
                                              "   ExpenseID=" + expId, dbConnection);

          SqlDataAdapter adapter = new SqlDataAdapter(command);

          // Declare a DataTable object that will hold the return value


          // Try to connect to the database, and use the adapter to fill the table
          try
          {
              dbConnection.Open();
              command.ExecuteNonQuery();
          }
          catch (Exception ex)
          {
              MessageBox.Show("del" + ex.Message);
          }
          finally
          {
              dbConnection.Close();
          }
      }
Ejemplo n.º 3
0
        private void DelPayroll(string id)
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand(" Delete from tblPayroll where EmployeeId=" + id +
                                                "and PaymentDate='" + payDate + "'", dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value


            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                dbConnection.Close();
            }

            updateHourIsPaid("0");
        }
Ejemplo n.º 4
0
        private void DelSaleProduct(string eventProductId, string salQuantity)
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand("Delete from tblSaleProducts where EventProductId=" + eventProductId +
                                                "  and SaleID=" + SaleID, dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value


            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("del" + ex.Message);
            }
            finally
            {
                dbConnection.Close();
            }

            ///
            dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            command = new SqlCommand(" Update [tblEventProduct] set Quantity= Quantity+ " + salQuantity + "," +
                                     " soldQuantity= soldQuantity-" + salQuantity + " where EventProductID=" + eventProductId, dbConnection);

            adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value


            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("update" + ex.Message);
            }
            finally
            {
                dbConnection.Close();
            }

            fillSaleGrid();
        }
Ejemplo n.º 5
0
        private void FillGridStock(string sql)
        {
            string connectionString = DBMethod.GetConnectionString();

            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "Stock_query");
            connection.Close();
            grdStock.DataSource = ds;
            grdStock.DataMember = "Stock_query";
        }
Ejemplo n.º 6
0
        private void FillPayGrid(string sql)
        {
            string connectionString = DBMethod.GetConnectionString();

            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "FullPayroll");
            connection.Close();
            grdPayroll.DataSource = ds;
            grdPayroll.DataMember = "FullPayroll";
        }
Ejemplo n.º 7
0
        private void GetPaymentDate()
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand("SELECT DISTINCT PaymentDate AS Expr1 FROM  [tblFullTimePayroll]", dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value
            DataTable dt = new DataTable();

            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                adapter.Fill(dt);

                if (dt.Rows.Count == 0)
                {
                    MessageBox.Show("No previous payroll are registered", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    radNew.Checked    = true;
                    radExists.Checked = false;
                }
                else
                {
                    cmbPaymentDate.Enabled = true;
                    cmbPaymentDate.Focus();
                }
                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        DateTime date = DateTime.Parse(row[0].ToString());
                        AuntRosieApplication.Classes.ListItem itm = new AuntRosieApplication.Classes.ListItem();
                        itm.name = date.Date.ToShortDateString();
                        itm.id   = date.Date.ToShortDateString();
                        cmbPaymentDate.Items.Add((Object)itm);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                dbConnection.Close();
            }
        }
Ejemplo n.º 8
0
        private void btnClear_Click(object sender, EventArgs e)
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand("Delete from tblSaleProducts where  SaleID=" + SaleID, dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);


            try
            {
                dbConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("del" + ex.Message);
            }
            finally
            {
                dbConnection.Close();
            }

            dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            command = new SqlCommand("Delete from tblSale where  SaleID=" + SaleID, dbConnection);

            adapter = new SqlDataAdapter(command);


            try
            {
                dbConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("del" + ex.Message);
            }
            finally
            {
                dbConnection.Close();
            }
            fillSaleGrid();
            clearData();
        }
Ejemplo n.º 9
0
        private void btnDestroy_Click(object sender, EventArgs e)
        {
            string updateSQLText = "Update [tblIngredientInventory]  Set tblIngredientInventory.Quantity=0 " +
                                   "where  (tblIngredientInventory.Quantity > 0)  " + expierdWhere;

            if (InventoryIngredient.RidOutExpierd(DBMethod.GetConnectionString(), updateSQLText))
            {
                MessageBox.Show("Selected expired items have been rid out", "Confirmation"
                                , MessageBoxButtons.OK, MessageBoxIcon.Information);
                chkExpierd_CheckedChanged(sender, e);
            }
            else
            {
                MessageBox.Show("Sorry! An internal error has happened", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 10
0
        private void calcRevenue()
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            string sql = "SELECT        SUM(tblEventProduct.soldQuantity * tblProductItem.Price) AS SalesPrice " +
                         " FROM tblEventProduct INNER JOIN " +
                         " tblProduction ON tblEventProduct.ProductionID = tblProduction.ProductionID INNER JOIN " +
                         " tblProductItem ON tblProduction.ProductItemID = tblProductItem.ProductItemID INNER JOIN " +
                         " tblEvent ON tblEventProduct.EventID = tblEvent.EventID";

            if (!chkAlltime.Checked)
            {
                sql = sql + " WHERE(tblEvent.EventDate BETWEEN'" + dtpFormDate.Value.Date.ToShortDateString() + "' AND '" + dtpToDate.Value.Date.ToShortDateString() + "')";
            }
            SqlCommand command = new SqlCommand(sql, dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value
            DataTable dt = new DataTable();

            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                adapter.Fill(dt);

                if (dt.Rows.Count == 0)
                {
                    lblITotRevenue.Text = "$0.00";
                }

                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        lblITotRevenue.Text = double.Parse(row[0].ToString()).ToString("C");
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 11
0
        private void calcExp()
        {
            string sql = "SELECT        SUM(Amount) AS Expr1 FROM  (SELECT        PaymentDate, Amount  FROM            tblFullTimePayroll " +
                         " UNION ALL  SELECT PaymentDate, Amount FROM tblPayroll " +
                         " UNION ALL SELECT ExpensePayDate, ExpenseValue FROM tblMiscellaneousExpense " +
                         " UNION ALL  SELECT PurchaseDate, Cost FROM tblIngredientInventory) AS derivedtbl_1 ";

            if (!chkAlltime.Checked)
            {
                sql += "  WHERE(PaymentDate BETWEEN'" + dtpFormDate.Value.Date.ToShortDateString() + "' AND '" + dtpToDate.Value.Date.ToShortDateString() + "')";
            }
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand(sql, dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value
            DataTable dt = new DataTable();

            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                adapter.Fill(dt);

                if (dt.Rows.Count == 0)
                {
                    lblITotExpenses.Text = "$0.00";
                }

                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        lblITotExpenses.Text = double.Parse(row[0].ToString()).ToString("C");
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 12
0
        private void GetQuantityType()
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand("SELECT    SUM(tblIngredientInventory.Quantity) AS Expr1, tblIngredient.Unit, tblIngredientType.IngredientTypeID" +
                                                "  FROM            tblIngredientInventory INNER JOIN " +
                                                " tblIngredient ON tblIngredientInventory.IngredientID = tblIngredient.IngredientID INNER JOIN " +
                                                " tblIngredientType ON tblIngredient.IngredientTypeID = tblIngredientType.IngredientTypeID " +
                                                "GROUP BY tblIngredient.Unit, tblIngredientType.IngredientTypeID" +
                                                " HAVING(tblIngredientType.IngredientTypeID = " + DBMethod.GetSelectedItemID(cmbType) + ") ", dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value
            DataTable dt = new DataTable();

            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                adapter.Fill(dt);

                if (dt.Rows.Count == 0)
                {
                    lblQuantityType.Text = "0.00";
                }
                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        lblQuantityType.Text = row[0].ToString() + "  " + row[1].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                dbConnection.Close();
            }
        }
Ejemplo n.º 13
0
        private void FillPayGridPart()
        {
            string sql = "  SELECT   tblPayroll.PaymentDate, tblPayroll.Amount, tblEmployee.EmployeeID, tblPayroll.FromDate, tblPayroll.ToDate," +
                         "   CASE WHEN PaymentMethod = 'r' THEN 'Credit' ELSE CASE WHEN PaymentMethod = 'c' THEN 'Cash' ELSE CASE WHEN PaymentMethod = 'd' THEN 'Debit' END END END AS PaymentMethod" +
                         " FROM tblEmployee INNER JOIN " +
                         " tblPayroll ON tblEmployee.EmployeeID = tblPayroll.EmployeeID WHERE tblPayroll.EmployeeID = " + DBMethod.GetSelectedItemID(cmbEmployeeName);;

            string connectionString = DBMethod.GetConnectionString();

            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "PayrollPart");
            connection.Close();
            grdPayrollPart.DataSource = ds;
            grdPayrollPart.DataMember = "PayrollPart";
        }
        private void calcSales()
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand("SELECT SUM(tblEventProduct.Quantity* tblProductItem.Price) AS SalesPrice, tblEventProduct.EventID" +
                                                " FROM            tblEventProduct INNER JOIN " +
                                                "  tblProduction ON tblEventProduct.ProductionID = tblProduction.ProductionID INNER JOIN " +
                                                "   tblProductItem ON tblProduction.ProductItemID = tblProductItem.ProductItemID " +
                                                " GROUP BY tblEventProduct.EventID " +
                                                " HAVING(tblEventProduct.EventID = " + DBMethod.GetSelectedItemID(cmbEventName) + ")", dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value
            DataTable dt = new DataTable();

            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                adapter.Fill(dt);

                if (dt.Rows.Count == 0)
                {
                    lblRevenue.Text       = "$0.00";
                    lblIngrdeintCost.Text = "$0.00";
                }

                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        lblRevenue.Text       = double.Parse(row[0].ToString()).ToString("C");
                        lblIngrdeintCost.Text = (double.Parse(row[0].ToString()) * 0.28).ToString("C");
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 15
0
        private void FillPayGridFull()
        {
            string sql = "SELECT        EmployeeID, PaymentDate, Month,  Amount, Year, " +
                         " CASE WHEN tblFullTimePayroll.PaymentMethod = 'r' THEN 'Credit' ELSE CASE WHEN tblFullTimePayroll.PaymentMethod = 'c' THEN 'Cash' ELSE CASE WHEN tblFullTimePayroll.PaymentMethod = 'd' THEN 'debit' END END END," +
                         " CASE WHEN BiWeekNo = 1 THEN 'First 2 weeks' ELSE CASE WHEN BiWeekNo = 2 THEN 'Last 2 Weeks' END END" +

                         " AS BiWeekNo  FROM   tblFullTimePayroll  where EmployeeID = " + DBMethod.GetSelectedItemID(cmbEmployeeName);

            string connectionString = DBMethod.GetConnectionString();

            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "PayrollFull");
            connection.Close();
            grdPayrollFull.DataSource = ds;
            grdPayrollFull.DataMember = "PayrollFull";
        }
Ejemplo n.º 16
0
      private void fillExpenseGrid()
      {
          String sql = "SELECT        ExpenseID, ExpensePayDate, ExpenseValue, ExpenseNote, " +
                       " CASE WHEN PaymentMethod = 'r' THEN 'Credit' ELSE CASE WHEN PaymentMethod = 'c' THEN 'Cash' ELSE CASE WHEN PaymentMethod = 'd' THEN 'Debit' END END END AS PaymentMethod, " +
                       " CASE WHEN ExpenseType = 'T' THEN 'Tansportation' ELSE CASE WHEN ExpenseType = 'U' THEN 'Utility Bill' ELSE CASE WHEN ExpenseType = 'M' THEN 'Maintenance Fee' ELSE CASE WHEN ExpenseType = 'O' THEN 'Maintenance Fee' " +
                       " END END END END AS ExpenseType " +
                       " FROM tblMiscellaneousExpense" +
                       " WHERE(ExpensePayDate = '" + dtpFormDate.Value.Date.ToShortDateString() + "')";

          string connectionString = DBMethod.GetConnectionString();

          SqlConnection  connection  = new SqlConnection(connectionString);
          SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
          DataSet        ds          = new DataSet();

          connection.Open();
          dataadapter.Fill(ds, "ExpensDet");
          connection.Close();
          grdExpenses.DataSource = ds;
          grdExpenses.DataMember = "ExpensDet";
      }
Ejemplo n.º 17
0
        private void fillSaleGrid()
        {
            String sql = "SELECT        tblSale.SaleID, tblSaleProducts.SaleQuantity, tblSaleProducts.SalePrice, tblSaleProducts.SaleQuantity * tblSaleProducts.SalePrice AS itemCost, tblCustomer.CustomerFirstName, tblCustomer.CustomerLastName," +
                         " tblSale.SaleDateTime, tblSale.PaymentMethod, tblProductSize.SizeName, tblProduct.ProductName, tblSaleProducts.EventProductID " +
                         " FROM            tblSaleProducts INNER JOIN " +
                         " tblSale ON tblSaleProducts.SaleID = tblSale.SaleID INNER JOIN " +
                         " tblCustomer ON tblSale.CustomerID = tblCustomer.CustomerID INNER JOIN " +
                         " tblEventProduct ON tblSaleProducts.EventProductID = tblEventProduct.EventProductID INNER JOIN " +
                         " tblProduction ON tblEventProduct.ProductionID = tblProduction.ProductionID INNER JOIN " +
                         " tblProductItem ON tblProduction.ProductItemID = tblProductItem.ProductItemID INNER JOIN " +
                         " tblProductSize ON tblProductItem.SizeID = tblProductSize.SizeID INNER JOIN " +
                         " tblProduct ON tblProductItem.ProductID = tblProduct.ProductID " +
                         " WHERE(tblSale.SaleID = " + SaleID.ToString() + ")";

            string connectionString = DBMethod.GetConnectionString();

            SqlConnection  connection  = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
            DataSet        ds          = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "SaleDet");
            connection.Close();
            grdSale.DataSource = ds;
            grdSale.DataMember = "SaleDet";



            if (grdSale.Rows.Count > 0)
            {
                btnClear.Enabled = true;
                btnSave.Enabled  = true;
                calcBill();
            }
            else
            {
                btnClear.Enabled = false;
                btnSave.Enabled  = false;
            }
        }
        private void FillHours()
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand command = new SqlCommand("SELECT  SUM(Hours) AS exp1 " +
                                                " FROM(SELECT        tblEmployeeHours.EmployeeID, tblEmployeeHours.EventID, tblEmployeeHours.Hours," +
                                                " tblEmployeeHours.IsPaid, tblEvent.EventID AS Expr1, tblEvent.EventName, tblEvent.LocationID, tblEvent.EventDate, " +
                                                " tblEvent.EventType FROM    tblEmployeeHours INNER JOIN   tblEvent ON tblEmployeeHours.EventID = tblEvent.EventID " +
                                                " WHERE(tblEvent.EventID =" + DBMethod.GetSelectedItemID(cmbEventName) + ")) AS derivedtbl_1" +
                                                " GROUP BY EventID  HAVING(EventID = " + DBMethod.GetSelectedItemID(cmbEventName) + ")", dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value
            DataTable dt = new DataTable();

            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                adapter.Fill(dt);

                if (dt.Rows.Count == 0)
                {
                    lblHour.Text = "0.0";
                }

                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        lblHour.Text = (double.Parse(row[0].ToString()) * HoursWages).ToString("C");
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 19
0
        private void FillProduct(String eventID)

        {
            string sqlEventText = "SELECT  tblEventProduct.EventProductID, tblProduct.ProductName, tblProduct.ProductType " +
                                  "FROM tblEventProduct INNER JOIN " +
                                  "tblProduction ON tblEventProduct.ProductionID = tblProduction.ProductionID INNER JOIN " +
                                  "tblProductItem ON tblProduction.ProductItemID = tblProductItem.ProductItemID INNER JOIN " +
                                  "tblProductSize ON tblProductItem.SizeID = tblProductSize.SizeID INNER JOIN " +
                                  "tblProduct ON tblProductItem.ProductID = tblProduct.ProductID " +
                                  " WHERE        tblEventProduct.EventID = " + eventID + " and tblEventProduct.Quantity > tblEventProduct.soldQuantity";

            // Declare the connection
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            // Create new SQL command
            SqlCommand     command = new SqlCommand(sqlEventText, dbConnection);
            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value
            DataTable productTable = new DataTable();

            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                adapter.Fill(productTable);
                cmbProduct.Items.Clear();
                DBMethod.FillCombBoxPerson(productTable, cmbProduct);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                dbConnection.Close();
            }

            // Return the populated DataTable
        }
Ejemplo n.º 20
0
        private void DelPayroll(string id, string year, string month, string biweek)
        {
            SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

            if (biweek == "First 2 weeks")
            {
                biweek = "1";
            }
            else
            {
                biweek = "2";
            }
            // Create new SQL command
            SqlCommand command = new SqlCommand(" Delete from [tblFullTimePayroll] where EmployeeId=" + id +
                                                " and Month=" + month + " and Year=" + year + " and BiweekNo=" + biweek, dbConnection);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            // Declare a DataTable object that will hold the return value


            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                dbConnection.Close();
            }
        }
        private void fillGrid()
        {
            string sql = "";

            if (chkAlltime.Checked)
            {
                if (chkExpenType.Checked)

                {
                    sql = sqltext + " " + sqlOrder;
                    if (!chkPay.Checked)
                    {
                        sql = sqltext + " where " + sqlWherePayMethod + " " + sqlOrder;
                    }
                }
                else

                {
                    sql = sqltext + " where" + sqlWhereType + " " + sqlOrder;
                    if (!chkPay.Checked)
                    {
                        sql = sqltext + " where " + sqlWhereType + " and " + sqlWherePayMethod + " " + sqlOrder;
                    }
                }
            }
            else
            {
                if (chkExpenType.Checked)
                {
                    sql = sqltext + " where" + sqlWhereTime + " " + sqlOrder;
                    if (!chkPay.Checked)
                    {
                        sql = sqltext + " where" + sqlWhereTime + " and " + sqlWherePayMethod + " " + sqlOrder;
                    }
                }
                else
                {
                    sql = sqltext + " where" + sqlWhereType + " and  " + sqlWhereTime + " " + sqlOrder;
                    if (!chkPay.Checked)
                    {
                        sql = sqltext + " where" + sqlWhereType + " and  " + sqlWhereTime + "  and " + sqlWherePayMethod + " " + sqlOrder;
                    }
                }
            }


            string         connectionString = DBMethod.GetConnectionString();
            SqlConnection  connection       = new SqlConnection(connectionString);
            SqlDataAdapter dataadapter      = new SqlDataAdapter(sql, connection);
            DataSet        ds = new DataSet();

            connection.Open();
            dataadapter.Fill(ds, "ExpenCost");
            connection.Close();
            grdCost.DataSource = ds;
            grdCost.DataMember = "ExpenCost";
            if (grdCost.Rows.Count == 0)
            {
                MessageBox.Show("No reults are founded", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            calcTotal();
        }
Ejemplo n.º 22
0
        private void cmbPartEmp_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbPartEmp.SelectedItem != null)
            {
                txtwage.Text       = "";
                lblHour.Text       = "";
                lblPartAmount.Text = "";

                if (lblDays.Text.Length > 0)
                {
                    txtwage.Focus();
                    SqlConnection dbConnection = new SqlConnection(DBMethod.GetConnectionString());

                    // Create new SQL command
                    SqlCommand command = new SqlCommand("SELECT  SUM(Hours) AS exp1 " +
                                                        " FROM(SELECT        tblEmployeeHours.EmployeeID, tblEmployeeHours.EventID, tblEmployeeHours.Hours," +
                                                        " tblEmployeeHours.IsPaid, tblEvent.EventID AS Expr1, tblEvent.EventName, tblEvent.LocationID, tblEvent.EventDate, " +
                                                        " tblEvent.EventType FROM    tblEmployeeHours INNER JOIN   tblEvent ON tblEmployeeHours.EventID = tblEvent.EventID " +
                                                        " WHERE(tblEvent.EventDate BETWEEN '" + dtpFormDate.Value.Date.ToShortDateString() + "' AND '" +
                                                        dtpToDate.Value.Date.ToShortDateString() + "' )) AS derivedtbl_1" +
                                                        " GROUP BY EmployeeID  HAVING(EmployeeID = " + DBMethod.GetSelectedItemID(cmbPartEmp) + ")", dbConnection);

                    SqlDataAdapter adapter = new SqlDataAdapter(command);

                    // Declare a DataTable object that will hold the return value
                    DataTable dt = new DataTable();

                    // Try to connect to the database, and use the adapter to fill the table
                    try
                    {
                        dbConnection.Open();
                        adapter.Fill(dt);
                        btnAddPart.Enabled = true;
                        if (dt.Rows.Count == 0)
                        {
                            btnAddPart.Enabled = false;
                            lblHour.Text       = "0.0";
                        }

                        if (dt != null)
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                lblHour.Text = String.Format("{0:0.0}", row[0].ToString());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        dbConnection.Close();
                    }
                }
                else
                {
                    MessageBox.Show("From Date should be before To Date ", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (lblHour.Text.Trim() == "0")
                {
                    pnlPartAddPayroll.Enabled = false;
                }
                else
                {
                    pnlPartAddPayroll.Enabled = true;
                }
            }
        }