コード例 #1
0
        private void EditData()
        {
            try
            {
                if (dataGridSalary.RowCount > 0)
                {
                    int    index    = dataGridSalary.SelectedCells[0].RowIndex;
                    string SalaryId = (string)dataGridSalary["SalaryId", index].Value;

                    var result = SalaryProcessor.FindDataBySalaryId(SalaryId, SalaryProcessor.loadCsvFileSalary(SalaryProcessor.pathSalary));

                    using (fmInputSalary f = new fmInputSalary())
                    {
                        f.lblSalaryId.Text         = result.SalaryId;
                        f.cbEmployee.SelectedValue = result.EmpCode;//still in problem
                        f.txtSalary.Text           = result.Salary;
                        f.txtTax.Text   = result.Tax;
                        f.txtTotal.Text = result.Total;
                        f.lblFlag.Text  = "edit";
                        f.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private void UpdateData()
        {
            try
            {
                SalaryModel model = new SalaryModel()
                {
                    Salary  = txtSalary.Text.Trim(),
                    Tax     = txtTax.Text.Trim(),
                    Total   = txtTotal.Text.Trim(),
                    EmpCode = cbEmployee.SelectedValue.ToString()
                };
                if (SalaryProcessor.UpdateDataIntoCsv(lblSalaryId.Text.Trim(), SalaryProcessor.loadCsvFileSalary(SalaryProcessor.pathSalary), model))
                {
                    MessageBox.Show("Update Data Successfull!");
                }
                else
                {
                    MessageBox.Show("Failed Update Data!");
                }

                //var principalForm = Application.OpenForms.OfType<UserControlMaster>().FirstOrDefault();
                //principalForm.LoadDataMaster();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("failed UpdateData: " + ex.Message.ToString());
            }
        }
コード例 #3
0
 private void InsertData()
 {
     try
     {
         SalaryModel model = new SalaryModel()
         {
             SalaryId = lblSalaryId.Text.Trim(),
             Salary   = txtSalary.Text.Trim(),
             Tax      = txtTax.Text.Trim(),
             Total    = txtTotal.Text.Trim(),
             EmpCode  = cbEmployee.SelectedValue.ToString()
         };
         if (SalaryProcessor.InsertDataIntoCsv(model))
         {
             MessageBox.Show("Insert Data Successfull!");
         }
         else
         {
             MessageBox.Show("Failed Insert Data!");
         }
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("failed InsertData: " + ex.Message.ToString());
     }
 }
コード例 #4
0
 private void BtnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         fmInputSalary f = new fmInputSalary();
         f.lblFlag.Text     = "new";
         f.lblSalaryId.Text = SalaryProcessor.LastSalaryId().ToString();
         f.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
 }
コード例 #5
0
        private void RdSortByName_CheckedChanged(object sender, EventArgs e)
        {
            if (rdSortByName.Checked == true)
            {
                try
                {
                    List <SalaryModel>   salary   = SalaryProcessor.loadCsvFileSalary(SalaryProcessor.pathSalary);
                    List <EmployeeModel> employee = MasterProcessor.loadCsvFileEmployee(MasterProcessor.pathEmployee);

                    dataGridSalary.DataSource = SalaryProcessor.BubleSortingSalary(SalaryProcessor.MergeSalary(salary, employee), "name");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
コード例 #6
0
        public void LoadDataSalary()
        {
            try
            {
                List <SalaryModel>   salary   = SalaryProcessor.loadCsvFileSalary(SalaryProcessor.pathSalary);
                List <EmployeeModel> employee = MasterProcessor.loadCsvFileEmployee(MasterProcessor.pathEmployee);

                dataGridSalary.DataSource = SalaryProcessor.MergeSalary(salary, employee);

                rdSortByCode.Checked   = false;
                rdSortByName.Checked   = false;
                rdSortBySalary.Checked = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
コード例 #7
0
        private void RemoveItem()
        {
            try
            {
                if (dataGridMaster.RowCount > 0)
                {
                    int    index = dataGridMaster.SelectedCells[0].RowIndex;
                    string code  = (string)dataGridMaster["Code", index].Value;

                    bool found      = false;
                    var  checkExist = SalaryProcessor.loadCsvFileSalary(SalaryProcessor.pathSalary);
                    foreach (var item in checkExist)
                    {
                        if (item.EmpCode.Trim().ToLower() == code.Trim().ToLower())
                        {
                            found = true;
                        }
                    }

                    if (!found)
                    {
                        DialogResult msg = MessageBox.Show("Do you want to delete this data?", "Confirmation", MessageBoxButtons.YesNo);
                        if (msg == DialogResult.Yes)
                        {
                            if (MasterProcessor.RemoveItemOnList(code, MasterProcessor.loadCsvFileEmployee(MasterProcessor.pathEmployee)))
                            {
                                MessageBox.Show("Delete data successfull!");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Sorry! This data cannot be Delete, It is Relate to another!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
コード例 #8
0
        private void RemoveItem()
        {
            try
            {
                if (dataGridSalary.RowCount > 0)
                {
                    int    index    = dataGridSalary.SelectedCells[0].RowIndex;
                    string SalaryId = (string)dataGridSalary["SalaryId", index].Value;

                    DialogResult msg = MessageBox.Show("Do you want to delete this data?", "Confirmation", MessageBoxButtons.YesNo);
                    if (msg == DialogResult.Yes)
                    {
                        if (SalaryProcessor.RemoveItemOnList(SalaryId, SalaryProcessor.loadCsvFileSalary(SalaryProcessor.pathSalary)))
                        {
                            MessageBox.Show("Delete data successfull!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }