コード例 #1
0
        private void btnAutoGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                var endDateOfYear = DateTime.Parse("31/12/" + BasePostedDate.Year);
                if (!BasePostedDate.ToShortDateString().Equals(endDateOfYear.ToShortDateString()))
                {
                    XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResFAArmortizationEndDateOfYear"), ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtRefNo.Focus();
                    return;
                }

                //bat xem da co chung tu nhap bang tay hay tu dong
                var fixedAssetArmortizations = _fixedAssetArmortizationPresenter.Display(endDateOfYear.ToShortDateString(), CurrencyLocal);
                if (fixedAssetArmortizations != null && fixedAssetArmortizations.Count > 0)
                {
                    XtraMessageBox.Show("Năm " + endDateOfYear.Year + " đã tồn tại chứng từ hao mòn, hao mòn theo tiền địa phương!", ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtRefDate.Focus();
                    return;
                }
                if (CurrencyLocal == "USD" && CurrencyAccounting == CurrencyLocal)
                {
                    XtraMessageBox.Show("Đơn vị chưa có phát sinh tài sản theo loại tiền này!", ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtRefDate.Focus();
                    return;
                }
                _fixedAssetArmortizationPresenter.Display(long.Parse(KeyValue), CurrencyLocal, ((DateTime)dtPostDate.EditValue).Year);
                CurrencyCode = CurrencyLocal;
                if (FixedAssetArmortizationDetails == null || FixedAssetArmortizationDetails.Count <= 0)
                {
                    XtraMessageBox.Show("Chưa có tài sản được ghi tăng hoặc tài sản đã hao mòn hết!", ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                SaveVoucher();
                Cursor.Current = Cursors.Default;
            }
            catch (Exception)
            {
                Cursor.Current = Cursors.Default;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
コード例 #2
0
        protected override bool ValidData()
        {
            gridViewDetail.CloseEditor();
            gridViewDetail.UpdateCurrentRow();

            var endDateOfYear = DateTime.Parse("31/12/" + BasePostedDate.Year);

            if (string.IsNullOrEmpty(RefNo) || RefNo.Equals(""))
            {
                XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResFAArmortizationRefNo"),
                                    ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                txtRefNo.Focus();
                return(false);
            }
            if (!BasePostedDate.ToShortDateString().Equals(endDateOfYear.ToShortDateString()))
            {
                XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResFAArmortizationEndDateOfYear"),
                                    ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                txtRefNo.Focus();
                return(false);
            }
            if (FixedAssetArmortizationDetails == null || FixedAssetArmortizationDetails.Count <= 0)
            {
                XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResFAArmortizationDetails"),
                                    ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                txtRefNo.Focus();
                return(false);
            }
            //LinhMC comment
            //var sameFixedAssetId = false;
            //for (var i = 0; i < FixedAssetArmortizationDetails.Count; i++)
            //{
            //    for (var j = i + 1; j < FixedAssetArmortizationDetails.Count; j++)
            //    {
            //        if (FixedAssetArmortizationDetails[i].FixedAssetId == FixedAssetArmortizationDetails[j].FixedAssetId)
            //        {
            //            sameFixedAssetId = true;
            //            break;
            //        }
            //    }
            //    if (!sameFixedAssetId) continue;
            //    XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResSameFAArmortizationDetails"),
            //                        ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK,
            //                        MessageBoxIcon.Error);
            //    return false;
            //}

            //if (FixedAssetArmortizationDetails.GroupBy(n => n.FixedAssetId).Any(c => c.Count() > 1))
            //{
            //    XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResSameFAArmortizationDetails"),
            //                        ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK,
            //                        MessageBoxIcon.Error);
            //    return false;
            //}

            int i             = 0;
            var lstRowAmounts = new List <string>();

            foreach (var fixedAssetArmortizationDetail in FixedAssetArmortizationDetails)
            {
                // bắt lỗi thiếu thông tin trong tài khoản
                if (!ValidAccountDetail(fixedAssetArmortizationDetail))
                {
                    //XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResDetaiVoucherNotValid"), ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                if (fixedAssetArmortizationDetail.AmountOC == 0)
                {
                    lstRowAmounts.Add((i + 1).ToString());
                }
                if (fixedAssetArmortizationDetail.AccountNumber == null)
                {
                    XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResAccountNumber"),
                                        ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    return(false);
                }

                if (fixedAssetArmortizationDetail.CorrespondingAccountNumber == null)
                {
                    XtraMessageBox.Show("Tài khoản đối ứng không được để trống!",
                                        ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    return(false);
                }

                var isDetailValid = true;
                if (fixedAssetArmortizationDetail.DetailBy != null)
                {
                    var detailFieldNames = fixedAssetArmortizationDetail.DetailBy.Split(';');
                    detailFieldNames = detailFieldNames.Where(w => !w.Contains("ProjectId")).ToArray();
                    if (detailFieldNames.Any(t => fixedAssetArmortizationDetail.GetType().GetProperty(t) != null && fixedAssetArmortizationDetail.GetType().GetProperty(t).Name != "AccountingObjectId" && fixedAssetArmortizationDetail[t] != null))
                    {
                        isDetailValid = false;
                    }
                    if (!isDetailValid)
                    {
                        XtraMessageBox.Show(ResourceHelper.GetResourceValueByName("ResDetaiVoucherNotValid"), "Thống báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }
                }

                i++;
            }
            if (lstRowAmounts.Count > 0)
            {
                if (DialogResult.No == XtraMessageBox.Show("Số tiền bằng 0 tại dòng " + string.Join(", ", lstRowAmounts.ToArray()) + ". Bạn có muốn lưu chứng từ không?",
                                                           ResourceHelper.GetResourceValueByName("ResDetailContent"), MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    return(false);
                }
            }

            return(true);
        }