Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            DebtDetail detail = new DebtDetail();

            if (!string.IsNullOrWhiteSpace(txtThanhtien.Text) || DateTime.Compare(dtpPaymentDay.DateTime, UtilityFunction.minDate) > 0)
            {
                detail.SetCreate();
                //detail.Payment = CurrencyUtility.ToDecimal(txtThanhtien.Text);
                //detail.PaymentDate = UtilityFunction.GetDatetime(dtpPaymentDay);
                //detail.RequestPaymentCode = txtReqCode.Text;
                //detail.Note = txtNote.Text;
                detail.DebtId = m_Debt.DebtId;
                CoverObjectUtility.GetAutoBindingData(this, detail);
                //detail.DebtDetailId = string.IsNullOrWhiteSpace(txtDetailId.Text)==false? Convert.ToInt32(txtDetailId.Text):0;
            }
            else
            {
                detail = null;
            }
            m_Debt.Bill = txtBill.Text;
            try
            {
                using (IUnitOfWork uow = new UnitOfWork())
                {
                    if (detail != null)
                    {
                        DebtDetail exist = uow.DebtDetailRepository.Find(detail.DebtDetailId);
                        if (exist == null)
                        {
                            uow.DebtDetailRepository.Add(detail);
                            gridUtility.AddNewRow <DebtDetail>(detail);
                        }
                        else
                        {
                            uow.DebtDetailRepository.Update(detail);
                            gridUtility.UpdateRow <DebtDetail>(detail);
                        }
                    }
                    uow.DebtRepository.Update(m_Debt);
                    uow.Commit();
                }
                m_Debt.TotalPayment += detail.Payment;
                if (UpdateRow != null)
                {
                    UpdateRow(m_Debt, CRUD.Update);
                }
                gridView1.RefreshData();
            }
            catch
            {
            }
        }