Пример #1
0
        /*
         * public class ComboboxItem
         * {
         *  public string Text { get; set; }
         *  public string Value { get; set; }
         *  public override string ToString() { return Text; }
         * }
         *
         * private void DepartmentText_SelectedIndexChanged(object sender, EventArgs e)
         * {
         *  ComboBox DeptBox = (ComboBox)sender;
         *  int selectedIndex = DeptBox.SelectedIndex;
         *  int selectedValue = (int)DeptBox.SelectedValue;
         *
         *  ComboboxItem selectedDept = (ComboboxItem)DeptBox.SelectedItem;
         * }
         */

        private void CalcButton_Click(object sender, EventArgs e)
        {
            EmptyError.Hide();
            hours               = (int)HoursWorked.Value;
            initialpay          = Pay / 8;
            grosspay            = hours * initialpay;
            GrossPayText.Text   = "₱" + grosspay.ToString();
            finalpay            = grosspay * 0.80;
            DeductionsText.Text = "₱" + (grosspay - finalpay).ToString();
            NetPayText.Text     = "₱" + finalpay.ToString();

            if (string.IsNullOrWhiteSpace(EmployeeNameText.Text))
            {
                EmployeeNameText.Focus();
                MessageBox.Show("Please Provide Details!", "Opps! Something went wrong!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                EmptyError.Show();
            }
            else
            {
                con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/payroll_db.accdb");
                const string sql = "insert into employee(empname) values (@empname)";
                cmd = new OleDbCommand(sql, con);
                con.Open();
                cmd.Parameters.AddWithValue("@empname", EmployeeNameText.Text);
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Record Saved Successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Пример #2
0
        private void LogoutButton_Click(object sender, EventArgs e)
        {
            EmployeeNameText.Clear();
            Login login = new Login();

            login.Show();
            this.Hide();
        }
 private void Form1_Load(object sender, EventArgs e)
 {
     EmployeeNameText.Select();
 }
        private void CalcButton_Click(object sender, EventArgs e)
        {
            hours = (int)HoursWorked.Value;
            week  = (int)WeekChooser.Value;
            lates = (int)latechooser.Value;
            EmptyError.Hide();
            EmptyError1.Hide();
            totweekhour         = (int)WeekChooser.Value * 40;
            latefee             = Pay / 60 * (int)latechooser.Value;
            OTrate              = Pay * 1.25;
            totOT               = OTrate * hours;
            grosspay            = Pay * totweekhour;
            GrossPayText.Text   = "₱ " + grosspay.ToString();
            deduc               = grosspay * 0.20 + latefee;
            finalpay            = grosspay - deduc + totOT;
            DeductionsText.Text = "₱ " + deduc.ToString();
            NetPayText.Text     = "₱ " + finalpay.ToString();
            otPaytxt.Text       = "₱ " + totOT.ToString();
            totallatetxt.Text   = "₱ " + latefee.ToString();
            totWeektxt.Text     = week.ToString();
            totlatetxt.Text     = lates.ToString();
            totOTtxt.Text       = hours.ToString();
            GenInvoice.Enabled  = true;

            //(EmployeeNameText.TextLength >= 1 && empidtxt.TextLength >= 1 && WeekChooser.Minimum >= 1 && HoursWorked.Minimum >= 1)

            if (string.IsNullOrWhiteSpace(empidtxt.Text) || string.IsNullOrWhiteSpace(EmployeeNameText.Text) || WeekChooser.Minimum >= 1 && HoursWorked.Minimum >= 1)
            {
                var result = MessageBox.Show("Opps! Something went wrong!", "Please Provide Details!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                EmptyError.Show();
                EmptyError1.Show();
                //MessageBox.Show("There are still unsaved changes." + Environment.NewLine + "are you sure you want to continue?", "Textbox has been filled!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    empidtxt.Focus();
                    EmployeeNameText.Focus();
                    WeekChooser.Focus();
                    HoursWorked.Focus();
                }
            }
            else
            {
                string       action = "Add Employee Record";
                string       table  = "employee";
                string       eid    = "N/A";
                string       today  = DateTime.Now.ToString("dd/MM/yyyy h:mm tt");
                const string sql1   = "insert into audittrail (adminname,[action],[tablename],eid,[accesstime]) values (@adminname,@action,@tablename,@eid,@accesstime)";
                cmd1 = new OleDbCommand(sql1, con);
                cmd1.Parameters.AddWithValue("@adminname", adminlabel.Text);
                cmd1.Parameters.AddWithValue("[@action]", action);
                cmd1.Parameters.AddWithValue("[@tablename]", table);
                cmd1.Parameters.AddWithValue("[@eid]", eid);
                cmd1.Parameters.AddWithValue("[@accesstime]", today);

                const string sql = "insert into employee(empid,empname,deptid,dept) values (@empid,@empname,@deptid,@dept)";
                cmd = new OleDbCommand(sql, con);
                cmd.Parameters.AddWithValue("@empid", empidtxt.Text);
                cmd.Parameters.AddWithValue("@empname", EmployeeNameText.Text);
                cmd.Parameters.AddWithValue("@deptid", DepartmentText.SelectedValue);
                cmd.Parameters.AddWithValue("@dept", DepartmentText.Text);

                con.Open();
                int result = cmd.ExecuteNonQuery();
                cmd1.ExecuteNonQuery();

                if (result > 0)
                {
                    MessageBox.Show("Record Saved Successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    con.Close();
                }
                else
                {
                    MessageBox.Show("It seems that the record does not saved successfully", "Opps! Something went wrong!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    con.Close();
                }
            }


            /*
             * if (!string.IsNullOrWhiteSpace(empidtxt.Text) && !string.IsNullOrWhiteSpace(EmployeeNameText.Text) && WeekChooser.Minimum >= 1 && HoursWorked.Minimum >= 1)
             * {
             *  empidtxt.Focus();
             *  MessageBox.Show("Opps! Something went wrong!", "Please Provide Details!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *  EmptyError.Show();
             *  EmptyError1.Show();
             * }
             * else
             * {
             *  const string sql = "insert into employee(empid,empname,deptid,dept) values (@empid,@empname,@deptid,@dept)";
             *  cmd = new OleDbCommand(sql, con);
             *  con.Open();
             *  cmd.Parameters.AddWithValue("@empid", empidtxt.Text);
             *  cmd.Parameters.AddWithValue("@empname", EmployeeNameText.Text);
             *  cmd.Parameters.AddWithValue("@deptid", DepartmentText.SelectedValue);
             *  cmd.Parameters.AddWithValue("@dept", DepartmentText.Text);
             *  int result = cmd.ExecuteNonQuery();
             *
             *  if (result > 0)
             *  {
             *      MessageBox.Show("Record Saved Successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             *      con.Close();
             *  }
             *  else
             *  {
             *      MessageBox.Show("Opps! Something went wrong!", "Please Provide Details!!!!!!!!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *      con.Close();
             *  }
             * }
             * else if (string.IsNullOrWhiteSpace(EmployeeNameText.Text) || string.IsNullOrWhiteSpace(empidtxt.Text) || WeekChooser.Minimum == 0 || HoursWorked.Minimum == 0)
             * {
             *  empidtxt.Focus();
             *  MessageBox.Show("Opps! Something went wrong!", "Please Provide Details!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *  EmptyError.Show();
             *  EmptyError1.Show();
             * }*/
        }