예제 #1
0
 private void TxtEndDate_Validating(object sender, CancelEventArgs e)
 {
     if (_Tag == "" || ActiveControl == TxtEndDate)
     {
         return;
     }
     if (TxtEndDate.Text != "  /  /")
     {
         try
         {
             if (ClsGlobal.CheckDateInsideCompanyPeriod(Convert.ToDateTime(TxtEndDate.Text)) == 1)
             {
                 ClsGlobal.DateRangeMsg();
                 TxtEndDate.Focus();
             }
         }
         catch
         {
             MessageBox.Show("Please enter valid date.", "Mr. Solutions", MessageBoxButtons.OK, MessageBoxIcon.Error);
             TxtEndDate.Focus();
         }
     }
     else
     {
         ClsGlobal.DateRangeMsg();
         TxtEndDate.Focus();
     }
 }
예제 #2
0
        private void BtnOk_Click(object sender, EventArgs e)
        {
            if (ClsGlobal.CheckDateInsideCompanyPeriod(Convert.ToDateTime(TxtDate.Text)) == 1)
            {
                ClsGlobal.DateMitiRangeMsg();
                return;
            }

            if (string.IsNullOrEmpty(TxtVoucherNo.Text.Trim()))
            {
                MessageBox.Show("Voucher number cannot be left blank.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtVoucherNo.Focus();
                return;
            }
            if (TxtMiti.Text == "  /  /")
            {
                MessageBox.Show("Miti cannot be left blank.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtMiti.Focus();
                return;
            }

            if (TxtDate.Text == "  /  /")
            {
                MessageBox.Show("Date cannot be left blank.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtDate.Focus();
                return;
            }

            if (Grid.Rows.Count <= 0)
            {
                MessageBox.Show("Invoice details not found.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Grid.Focus();
                return;
            }

            if (Grid.Rows.Count == 1 && Grid.Rows[0].Cells["Particular"].Value == null)
            {
                MessageBox.Show("Invoice details not found.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                BtnOk.Enabled = false;
                Grid.Focus();
                return;
            }

            _objPurchaseIndent.Model.EntryFromProject = "Normal";
            _objPurchaseIndent.Model.Gadget           = "Desktop";

            _objPurchaseIndent.Model.VDate       = Convert.ToDateTime(TxtDate.Text);
            _objPurchaseIndent.Model.Tag         = _Tag;
            _objPurchaseIndent.Model.VoucherNo   = TxtVoucherNo.Text.Trim();
            _objPurchaseIndent.Model.VTime       = _objDate.GetServerDateTime();
            _objPurchaseIndent.Model.VMiti       = TxtMiti.Text;
            _objPurchaseIndent.Model.RequestedBy = txtRequestedBy.Text;
            if (!string.IsNullOrEmpty(TxtDepartment.Text))
            {
                string[] dept = TxtDepartment.Tag.ToString().Split('|');
                _objPurchaseIndent.Model.DepartmentId1 = ((dept[0].ToString() == "") ? 0 : Convert.ToInt32(dept[0].ToString()));
                _objPurchaseIndent.Model.DepartmentId2 = ((dept[1].ToString() == "") ? 0 : Convert.ToInt32(dept[1].ToString()));
                _objPurchaseIndent.Model.DepartmentId3 = ((dept[2].ToString() == "") ? 0 : Convert.ToInt32(dept[2].ToString()));
                _objPurchaseIndent.Model.DepartmentId4 = ((dept[3].ToString() == "") ? 0 : Convert.ToInt32(dept[3].ToString()));
            }
            _objPurchaseIndent.Model.Remarks       = TxtRemarks.Text;
            _objPurchaseIndent.Model.BranchId      = ClsGlobal.BranchId;
            _objPurchaseIndent.Model.CompanyUnitId = ClsGlobal.CompanyUnitId;

            PurchaseIndentDetailsViewModel _PurchaseIndentDetails = null;
            int dc = Grid.Rows.Count;

            foreach (DataGridViewRow ro in Grid.Rows)
            {
                if (ro.Cells["Particular"].Value != null)
                {
                    _PurchaseIndentDetails = new PurchaseIndentDetailsViewModel
                    {
                        VoucherNo = _objPurchaseIndent.Model.VoucherNo,
                        Sno       = Grid.Rows.IndexOf(ro) + 1,
                        ProductId = Convert.ToInt32(ro.Cells["ProductId"].Value.ToString())
                    };

                    if (ro.Cells["AltQty"].Value != null)
                    {
                        decimal.TryParse(ro.Cells["AltQty"].Value.ToString().Trim(), out decimal _AltQty);
                        _PurchaseIndentDetails.AltQty = _AltQty;
                    }
                    else
                    {
                        _PurchaseIndentDetails.AltQty = 0;
                    }

                    if (ro.Cells["AltQty"].Value != null)
                    {
                        _PurchaseIndentDetails.ProductAltUnitId = !string.IsNullOrEmpty(ro.Cells["ProductAltUnitId"].Value.ToString()) ? Convert.ToInt32(ro.Cells["ProductAltUnitId"].Value.ToString()) : 0;
                    }

                    _PurchaseIndentDetails.Qty = ro.Cells["Qty"].Value != null?Convert.ToDecimal(ro.Cells["Qty"].Value.ToString().Trim()) : 0;

                    if (ro.Cells["ProductUnitId"].Value != null)
                    {
                        _PurchaseIndentDetails.ProductUnitId = string.IsNullOrEmpty(ro.Cells["ProductUnitId"].Value.ToString()) ? 0 : Convert.ToInt32(ro.Cells["ProductUnitId"].Value.ToString());
                    }
                    else
                    {
                        _PurchaseIndentDetails.ProductUnitId = 0;
                    }

                    _PurchaseIndentDetails.ConversionRatio = ro.Cells["QtyConversion"].Value != null?Convert.ToDecimal(ro.Cells["QtyConversion"].Value.ToString().Trim()) : 0;

                    _PurchaseIndentDetails.Narration = ro.Cells["Narration"].Value.ToString();

                    _objPurchaseIndent.ModelDetails.Add(_PurchaseIndentDetails);
                }
            }

            _objPurchaseIndent.Model.DocId = Convert.ToInt32(TxtVoucherNo.Tag.ToString());
            string output = "";

            if (_Tag == "DELETE")
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure want to Delete Record..??", "Close Form", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.No)
                {
                    return;
                }
            }

            if (_Tag == "NEW")
            {
                if (ClsGlobal.ConfirmSave == 1)
                {
                    DialogResult dialogResult = MessageBox.Show("Are you sure want to Save New Record..??", "Close Form", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                    if (dialogResult == DialogResult.Yes)
                    {
                        output = _objPurchaseIndent.SavePurchaseIndent();
                    }
                }
                else
                {
                    output = _objPurchaseIndent.SavePurchaseIndent();
                }
            }
            else
            {
                output = _objPurchaseIndent.SavePurchaseIndent();
            }

            if (string.IsNullOrEmpty(output))
            {
                MessageBox.Show("Error occurred during data submission.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (_Tag == "NEW")
                {
                    MessageBox.Show("Voucher number : " + TxtVoucherNo.Text + " has been generated.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (_Tag == "EDIT")
                {
                    MessageBox.Show("Voucher number : " + TxtVoucherNo.Text + " has been updated.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (_Tag == "DELETE")
                {
                    MessageBox.Show("Voucher number : " + TxtVoucherNo.Text + " has been deleted.", "Mr Solution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                ClearFld();
                if (this._Tag == "NEW")
                {
                    _DocId         = Convert.ToInt32(TxtVoucherNo.Tag.ToString());
                    BtnNew.Enabled = true;
                    BtnNew.PerformClick();
                }
                else if (this._Tag == "EDIT")
                {
                    BtnEdit.Enabled = true;
                    BtnEdit.PerformClick();
                }
                else if (this._Tag == "DELETE")
                {
                    BtnDelete.Enabled = true;
                    BtnDelete.PerformClick();
                }
            }
        }