Exemple #1
0
        public static SalaryModel FindDataBySalaryId(string salaryId, List <SalaryModel> listOfModel)
        {
            SalaryModel model = new SalaryModel();

            try
            {
                bool found = false;
                int  b     = 0;
                while (b <= listOfModel.Count)
                {
                    if (listOfModel[b].SalaryId.ToLower() == salaryId.ToLower())
                    {
                        found = true;
                        break;
                    }

                    b++;
                }

                if (found)
                {
                    model.SalaryId = listOfModel[b].SalaryId.Trim();
                    model.EmpCode  = listOfModel[b].EmpCode.Trim();
                    model.Salary   = listOfModel[b].Salary.Trim();
                    model.Tax      = listOfModel[b].Tax.Trim();
                    model.Total    = listOfModel[b].Total.Trim();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error FindDataBySalaryId: " + ex.Message.ToString());
            }

            return(model);
        }
        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());
            }
        }
Exemple #3
0
        public static bool InsertDataIntoCsv(SalaryModel model)
        {
            bool isInsert = false;

            try
            {
                string StringContent = model.SalaryId + ";" + model.EmpCode + ";" + model.Salary + ";" + model.Tax + ";" + model.Total + ";";

                if (!File.Exists(pathSalary))
                {
                    File.WriteAllText(pathSalary, StringContent);
                    isInsert = true;
                }
                else
                {
                    File.AppendAllText(pathSalary, "\n" + StringContent);
                    isInsert = true;
                }
            }
            catch (Exception ex)
            {
                isInsert = false;
                throw new Exception("Error InsertDataIntoScv: " + ex.Message.ToString());
            }

            return(isInsert);
        }
 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());
     }
 }
Exemple #5
0
        public static bool UpdateDataIntoCsv(string salaryId, List <SalaryModel> listOfModel, SalaryModel model)
        {
            bool isUpdate = false;

            try
            {
                bool found = false;
                int  i     = 0;
                while (i <= listOfModel.Count)
                {
                    if (listOfModel[i].SalaryId.ToLower() == salaryId.ToLower())
                    {
                        found = true;
                        break;
                    }

                    i++;
                }

                if (found)
                {
                    listOfModel[i].EmpCode = model.EmpCode;
                    listOfModel[i].Salary  = model.Salary;
                    listOfModel[i].Tax     = model.Tax;
                    listOfModel[i].Total   = model.Total;
                }

                StringBuilder sb = new StringBuilder();
                foreach (var item in listOfModel)
                {
                    string StringContent = item.SalaryId + ";" + item.EmpCode + ";" + item.Salary + ";" + item.Tax + ";" + item.Total + ";";
                    sb.AppendLine(StringContent);
                }

                File.WriteAllText(pathSalary, sb.ToString().Trim());
                isUpdate = true;
            }
            catch (Exception ex)
            {
                throw new Exception("Error UpdateDataIntoCsv: " + ex.Message.ToString());
            }

            return(isUpdate);
        }