public bool Update(Expense_Vehicle expense_Vehicle)
 {
     try
     {
         var updateEntity = _expenseVehicleRepo.Find(expense_Vehicle.Id);
         AutoMapper.Mapper.DynamicMap(expense_Vehicle, updateEntity);
         _expenseVehicleRepo.Update(updateEntity);
         _uow.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Insert(Expense_Vehicle expense_Vehicle)
 {
     try
     {
         var newEntity = AutoMapper.Mapper.DynamicMap <Expense_Vehicle>(expense_Vehicle);
         newEntity.Status = Status.Active;
         _expenseVehicleRepo.Insert(newEntity);
         _uow.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (DailyCastingEntryType == 1)
            {
                #region Variables
                DateTime ExpenseDate  = Convert.ToDateTime(string.Format("{0: dd/MM/yyyy 00:00:00}", DateTime.Now));
                decimal  Price        = nudPrice.Value;
                string   Descriptions = txtDesciptions.Text;
                #endregion

                #region Service
                UnitofWork unitofWork = new UnitofWork(ctx);
                Expense_Vehicle_Service expense_Vehicle_Service = new Expense_Vehicle_Service(unitofWork);
                TotalExpenses_Service   totalExpenses_Service   = new TotalExpenses_Service(unitofWork);
                #endregion

                if (Price > 0 && !string.IsNullOrEmpty(Descriptions))
                {
                    DialogResult dialogResult = MessageBox.Show("Kaydı Eklemek İstediğinize Emin misiniz?", "Yeni Kayıt", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        Expense_Vehicle expense_Vehicle = new Expense_Vehicle()
                        {
                            ExpenseDate  = ExpenseDate,
                            Descriptions = Descriptions,
                            Price        = Price
                        };
                        if (expense_Vehicle_Service.Insert(expense_Vehicle))
                        {
                            TotalExpenses totalExpenses = totalExpenses_Service.GetTotalExpenses(ExpenseDate, ExpenseType.Vehicle);
                            if (totalExpenses != null)
                            {
                                totalExpenses.Price += Price;
                                if (totalExpenses_Service.Update(totalExpenses))
                                {
                                    MessageBox.Show("İşlem Başarılı.");

                                    txtDesciptions.Text = "";
                                    nudPrice.Value      = 0;
                                }
                                else
                                {
                                    MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                totalExpenses = new TotalExpenses()
                                {
                                    ExpenseDate            = ExpenseDate,
                                    ExpenseType            = ExpenseType.Vehicle,
                                    ExpenseTypeDesciptions = "Araç",
                                    Price  = Price,
                                    Status = Status.Active,
                                };
                                if (totalExpenses_Service.Insert(totalExpenses))
                                {
                                    MessageBox.Show("İşlem Başarılı.");

                                    txtDesciptions.Text = "";
                                    nudPrice.Value      = 0;
                                }
                                else
                                {
                                    MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Boş Geçilemez.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else if (DailyCastingEntryType == 2)
            {
                #region Variables
                DateTime    ExpenseDate = Convert.ToDateTime(string.Format("{0: dd/MM/yyyy 00:00:00}", DateTime.Now));
                InvoiceType invoiceType = new InvoiceType();
                switch (cmbInvoice.SelectedValue)
                {
                case "0":
                    invoiceType = InvoiceType.That; break;

                case "1":
                    invoiceType = InvoiceType.Electricity; break;

                case "2":
                    invoiceType = InvoiceType.NaturalGas; break;

                case "3":
                    invoiceType = InvoiceType.Internet; break;

                case "4":
                    invoiceType = InvoiceType.Other; break;

                default:
                    break;
                }
                string  Descriptions = txtDesciptions.Text;
                decimal Price        = nudPrice.Value;
                #endregion

                #region Service
                UnitofWork unitofWork = new UnitofWork(ctx);
                Expense_Invoice_Service expense_Invoice_Service = new Expense_Invoice_Service(unitofWork);
                TotalExpenses_Service   totalExpenses_Service   = new TotalExpenses_Service(unitofWork);
                #endregion

                if (Price > 0 && cmbInvoice.Text != "Fatura Tipi Seçiniz...")
                {
                    DialogResult dialogResult = MessageBox.Show("Kaydı Eklemek İstediğinize Emin misiniz?", "Yeni Kayıt", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        Expense_Invoice expense_Invoice = new Expense_Invoice()
                        {
                            ExpenseDate  = ExpenseDate,
                            InvoiceType  = enumHelper.GetEnumDescription(invoiceType),
                            Descriptions = Descriptions,
                            Price        = Price,
                            Status       = Status.Active
                        };
                        if (expense_Invoice_Service.Insert(expense_Invoice))
                        {
                            TotalExpenses totalExpenses = totalExpenses_Service.GetTotalExpenses(ExpenseDate, ExpenseType.Invoice);
                            if (totalExpenses != null)
                            {
                                totalExpenses.Price += Price;
                                if (totalExpenses_Service.Update(totalExpenses))
                                {
                                    MessageBox.Show("İşlem Başarılı.");

                                    cmbInvoice.SelectedIndex = 0;
                                    txtDesciptions.Text      = "";
                                    nudPrice.Value           = 0;
                                }
                                else
                                {
                                    MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                totalExpenses = new TotalExpenses()
                                {
                                    ExpenseDate            = ExpenseDate,
                                    ExpenseType            = ExpenseType.Invoice,
                                    ExpenseTypeDesciptions = "Fatura",
                                    Price  = Price,
                                    Status = Status.Active,
                                };
                                if (totalExpenses_Service.Insert(totalExpenses))
                                {
                                    MessageBox.Show("İşlem Başarılı.");

                                    cmbInvoice.SelectedIndex = 0;
                                    txtDesciptions.Text      = "";
                                    nudPrice.Value           = 0;
                                }
                                else
                                {
                                    MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Boş Geçilemez.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else if (DailyCastingEntryType == 3)
            {
                #region Variables
                DateTime ExpenseDate  = Convert.ToDateTime(string.Format("{0: dd/MM/yyyy 00:00:00}", DateTime.Now));
                string   SupplirsCode = cmbSuppliers.SelectedValue.ToString();
                decimal  Price        = nudPrice.Value;
                string   Descriptions = txtDesciptions.Text;
                #endregion

                #region Service
                UnitofWork unitofWork = new UnitofWork(ctx);
                SupplierCompanies_Service supplierCompanies_Service = new SupplierCompanies_Service(unitofWork);
                Expense_Suppliers_Service expense_Suppliers_Service = new Expense_Suppliers_Service(unitofWork);
                TotalExpenses_Service     totalExpenses_Service     = new TotalExpenses_Service(unitofWork);
                #endregion

                if (!string.IsNullOrEmpty(SupplirsCode) && Price > 0)
                {
                    DialogResult dialogResult = MessageBox.Show("Kaydı Eklemek İstediğinize Emin misiniz?", "Yeni Kayıt", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        SupplierCompanies supplierCompanies = supplierCompanies_Service.GetSupplierCompanies(SupplirsCode);
                        Expense_Suppliers expense_Suppliers = new Expense_Suppliers()
                        {
                            Status       = Status.Active,
                            ExpenseDate  = ExpenseDate,
                            Price        = Price,
                            Descriptions = Descriptions,
                            SupplierCode = supplierCompanies.Code,
                            SupplierName = supplierCompanies.Name
                        };
                        if (expense_Suppliers_Service.Insert(expense_Suppliers))
                        {
                            TotalExpenses totalExpenses = totalExpenses_Service.GetTotalExpenses(ExpenseDate, ExpenseType.Suppliers);
                            if (totalExpenses != null)
                            {
                                totalExpenses.Price += Price;
                                if (totalExpenses_Service.Update(totalExpenses))
                                {
                                    MessageBox.Show("İşlem Başarılı.");

                                    cmbSuppliers.SelectedIndex = 0;
                                    txtDesciptions.Text        = "";
                                    nudPrice.Value             = 0;
                                }
                                else
                                {
                                    MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                totalExpenses = new TotalExpenses()
                                {
                                    ExpenseDate            = ExpenseDate,
                                    ExpenseType            = ExpenseType.Suppliers,
                                    ExpenseTypeDesciptions = "Tedarikçi",
                                    Price  = Price,
                                    Status = Status.Active,
                                };
                                if (totalExpenses_Service.Insert(totalExpenses))
                                {
                                    MessageBox.Show("İşlem Başarılı.");

                                    cmbSuppliers.SelectedIndex = 0;
                                    txtDesciptions.Text        = "";
                                    nudPrice.Value             = 0;
                                }
                                else
                                {
                                    MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Boş Geçilemez.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else if (DailyCastingEntryType == 4)
            {
                #region Variables
                DateTime ExpenseDate      = Convert.ToDateTime(string.Format("{0: dd/MM/yyyy 00:00:00}", DateTime.Now));
                string   FullName         = cmbStaffs.Text;
                string   StaffExpenseType = cmbStaffExpense.Text;
                decimal  Price            = nudPrice.Value;
                #endregion

                #region Service
                UnitofWork            unitofWork            = new UnitofWork(ctx);
                Staff_Service         staff_Service         = new Staff_Service(unitofWork);
                Expense_Staff_Service expense_Staff_Service = new Expense_Staff_Service(unitofWork);
                TotalExpenses_Service totalExpenses_Service = new TotalExpenses_Service(unitofWork);
                #endregion

                if (!string.IsNullOrEmpty(FullName) && !string.IsNullOrEmpty(StaffExpenseType) && Price > 0)
                {
                    DialogResult dialogResult = MessageBox.Show("Kaydı Eklemek İstediğinize Emin misiniz?", "Yeni Kayıt", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        Expense_Staff expense_Staff = new Expense_Staff()
                        {
                            ExpenseDate      = ExpenseDate,
                            FullName         = FullName,
                            Price            = Price,
                            StaffExpenseType = StaffExpenseType,
                            Status           = Status.Active
                        };
                        if (expense_Staff_Service.Insert(expense_Staff))
                        {
                            TotalExpenses totalExpenses = totalExpenses_Service.GetTotalExpenses(ExpenseDate, ExpenseType.Staff);
                            if (totalExpenses != null)
                            {
                                totalExpenses.Price += Price;
                                if (totalExpenses_Service.Update(totalExpenses))
                                {
                                    MessageBox.Show("İşlem Başarılı.");

                                    cmbStaffs.SelectedIndex       = 0;
                                    cmbStaffExpense.SelectedIndex = 0;
                                    nudPrice.Value = 0;
                                }
                                else
                                {
                                    MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                totalExpenses = new TotalExpenses()
                                {
                                    ExpenseDate            = ExpenseDate,
                                    ExpenseType            = ExpenseType.Staff,
                                    ExpenseTypeDesciptions = "Personel",
                                    Price  = Price,
                                    Status = Status.Active,
                                };
                                if (totalExpenses_Service.Insert(totalExpenses))
                                {
                                    MessageBox.Show("İşlem Başarılı.");

                                    cmbStaffs.SelectedIndex       = 0;
                                    cmbStaffExpense.SelectedIndex = 0;
                                    nudPrice.Value = 0;
                                }
                                else
                                {
                                    MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Boş Geçilemez.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }