Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
C#
protected void btnSave_Click(object sender, EventArgs e)
    {
        uc = new UserCredential();
        ucTO = uc.GetUserCredential();

        ltrMessageCashReceived.Text = string.Empty;
        cSycMasterCode = new CSycMasterCode(HttpContext.Current.Request.RawUrl);
        List<sycmastercode> sycMasterCode = null;
        sycMasterCode = new List<sycmastercode>();

        cShmShareAllotment = new CShmShareAllotment(HttpContext.Current.Request.RawUrl);
        List<shmshareallotment> shmShareAllotment = null;
        shmShareAllotment = new List<shmshareallotment>();

        cAcoTransaction = new CAcoTransaction(HttpContext.Current.Request.RawUrl);
        List<acotransaction> acoTransaction = null;
        acoTransaction = new List<acotransaction>();

        GetTransection(ref acoTransaction, ref shmShareAllotment, ref sycMasterCode);
        msg = cAcoTransaction.CreateAcoTransactionCashReceive(acoTransaction, shmShareAllotment, sycMasterCode);

    }
    protected void GetTransection(ref List<acotransaction> acoTransaction, ref List<shmshareallotment> shmShareAllotment, ref List<sycmastercode> sycMasterCode)
    {
       
        CComCalender CComCalender = new CComCalender(HttpContext.Current.Request.RawUrl);
        string accountOpenEngDate = CComCalender.NepaliToEnglish(NepaliCalenderPicker.ShortNepaliDate).ToString(GlobalEnum.AppDateFormat.Format);

        cSycMasterCode = new CSycMasterCode(HttpContext.Current.Request.RawUrl);
        var sycMasterCodeShare = cSycMasterCode.GetBySycMasterCodeId(2);
        decimal shareNoFrom = sycMasterCodeShare.MasterCodeValue;

        cSycMasterCode = new CSycMasterCode(HttpContext.Current.Request.RawUrl);
        var sycMasterCodeTransection = cSycMasterCode.GetBySycMasterCodeId(4);

        cShmShareType = new CShmShareType(HttpContext.Current.Request.RawUrl);
        var shmShareTypePromoter = cShmShareType.GetByShmShareTypeId(1);

        cShmShareType = new CShmShareType(HttpContext.Current.Request.RawUrl);
        var shmShareTypeLoan = cShmShareType.GetByShmShareTypeId(2);

        cShmShareType = new CShmShareType(HttpContext.Current.Request.RawUrl);
        var shmShareTypeHolder = cShmShareType.GetByShmShareTypeId(3);

        for(int i=0; i<cashreceivelist.count;>        {
            acoTransaction = new List<acotransaction>();
            if(CashReceiveList[i].TransectionTypeId==1)
            {                
                acoTransaction[i].MemMemberRegistrationId =CashReceiveList[i].MemberRegistrationId;
                acoTransaction[i].MamAccountOpeningId = CashReceiveList[i].TransectionDetailsId;
                acoTransaction[i].AcoTransactionTypeId = CashReceiveList[i].TransectionTypeId;
                acoTransaction[i].HurCollectorId = CashReceiveList[i].CollectorId;
                acoTransaction[i].TransactionNumber = sycMasterCodeTransection.MasterCodeValue + 1;
                acoTransaction[i].CashReceived=CashReceiveList[i].Amount;
                acoTransaction[i].TransactionOn= Convert.ToDateTime(accountOpenEngDate);
                acoTransaction[i].TransactionOnBs=NepaliCalenderPicker.ShortNepaliDate;
                acoTransaction[i].UsmOfficeId=ucTO.OfficeId;
                acoTransaction[i].IsPosted=false;
                acoTransaction[i].Description=ASPxTxtRemarks.Text;
                acoTransaction[i].CreatedBy=ucTO.UserId;
                acoTransaction[i].CreatedOn=System.DateTime.Now;
                acoTransaction[i].IsCancelled=false;                   
            }
            else if (CashReceiveList[i].TransectionTypeId == 5 ||CashReceiveList[i].TransectionTypeId == 6 ||CashReceiveList[i].TransectionTypeId == 7)
            {
                acoTransaction[i].MemMemberRegistrationId = CashReceiveList[i].MemberRegistrationId;
                acoTransaction[i].LmtLoanIssueId = CashReceiveList[i].TransectionDetailsId;
                acoTransaction[i].AcoTransactionTypeId = CashReceiveList[i].TransectionTypeId;
                acoTransaction[i].HurCollectorId = Convert.ToInt64(ddlCollector.SelectedValue);
                acoTransaction[i].TransactionNumber = sycMasterCodeTransection.MasterCodeValue + 1;
                acoTransaction[i].CashReceived = CashReceiveList[i].Amount;
                acoTransaction[i].TransactionOn = Convert.ToDateTime(accountOpenEngDate);
                acoTransaction[i].TransactionOnBs = NepaliCalenderPicker.ShortNepaliDate;
                acoTransaction[i].UsmOfficeId = ucTO.OfficeId;
                acoTransaction[i].IsPosted = false;
                acoTransaction[i].Description = ASPxTxtRemarks.Text;
                acoTransaction[i].CreatedBy = ucTO.UserId;
                acoTransaction[i].CreatedOn = System.DateTime.Now;
                acoTransaction[i].IsCancelled = false;
            }
           else if (CashReceiveList[i].TransectionTypeId == 12)
            {
                acoTransaction[i].MemMemberRegistrationId = CashReceiveList[i].MemberRegistrationId;
                acoTransaction[i].AcoMiscellaneousChargesId = CashReceiveList[i].TransectionDetailsId;
                acoTransaction[i].AcoTransactionTypeId = CashReceiveList[i].TransectionTypeId;
                acoTransaction[i].HurCollectorId = Convert.ToInt64(ddlCollector.SelectedValue);
                acoTransaction[i].TransactionNumber = sycMasterCodeTransection.MasterCodeValue + 1;
                acoTransaction[i].CashReceived = CashReceiveList[i].Amount;
                acoTransaction[i].TransactionOn = Convert.ToDateTime(accountOpenEngDate);
                acoTransaction[i].TransactionOnBs = NepaliCalenderPicker.ShortNepaliDate;
                acoTransaction[i].UsmOfficeId = ucTO.OfficeId;
                acoTransaction[i].IsPosted = false;
                acoTransaction[i].Description = ASPxTxtRemarks.Text;
                acoTransaction[i].CreatedBy = ucTO.UserId;
                acoTransaction[i].CreatedOn = System.DateTime.Now;
                acoTransaction[i].IsCancelled = false;
            }
            else if (CashReceiveList[i].TransectionTypeId == 8)
            {
                acoTransaction[i].MemMemberRegistrationId = CashReceiveList[i].MemberRegistrationId;
                //acoTransaction[i].ShmShareAllotmentId = CashReceiveList[i].TransectionDetailsId;
                acoTransaction[i].ShmShareAllotmentId = 290;
                acoTransaction[i].AcoTransactionTypeId = CashReceiveList[i].TransectionTypeId;
                acoTransaction[i].HurCollectorId = Convert.ToInt64(ddlCollector.SelectedValue);
                acoTransaction[i].TransactionNumber = sycMasterCodeTransection.MasterCodeValue + 1;
                acoTransaction[i].CashReceived = CashReceiveList[i].Amount;
                acoTransaction[i].TransactionOn = Convert.ToDateTime(accountOpenEngDate);
                acoTransaction[i].TransactionOnBs = NepaliCalenderPicker.ShortNepaliDate;
                acoTransaction[i].UsmOfficeId = ucTO.OfficeId;
                acoTransaction[i].IsPosted = false;
                acoTransaction[i].Description = ASPxTxtRemarks.Text;
                acoTransaction[i].CreatedBy = ucTO.UserId;
                acoTransaction[i].CreatedOn = System.DateTime.Now;
                acoTransaction[i].IsCancelled = false;

                int j = 0; 

                if(CashReceiveList[i].TransectionDetails=="PROMOTER SHARE")
                {                    
                    shmShareAllotment[j].MemMemberRegistrationId = CashReceiveList[i].MemberRegistrationId;
                    shmShareAllotment[j].ShmShareTypeId = 1;
                    shmShareAllotment[j].ShareNo = CashReceiveList[i].ShareNo;
                    shmShareAllotment[j].ShareNoFrom = shareNoFrom + 1;
                    shmShareAllotment[j].ShareNoTo = shareNoFrom + CashReceiveList[i].ShareNo;
                    shmShareAllotment[j].SharePurchaseOn =Convert.ToDateTime(accountOpenEngDate);
                    shmShareAllotment[j].SharePurchaseOnBs = NepaliCalenderPicker.ShortNepaliDate;
                    shmShareAllotment[j].ShareFaceValue = shmShareTypePromoter.ShareFaceValue;
                    shmShareAllotment[j].SharePremium = shmShareTypePromoter.SharePremium;
                    shmShareAllotment[j].SharePurchaseAmount = CashReceiveList[i].Amount;
                    shmShareAllotment[j].Remarks = ASPxTxtRemarks.Text;
                    shmShareAllotment[j].CreatedBy = ucTO.UserId;
                    shmShareAllotment[j].CreatedOn = System.DateTime.Now;
                    shmShareAllotment[j].IsPosted = false;
                    shmShareAllotment[j].IsActive = true;
                    shmShareAllotment[j].IsReturned = false;
                    j++;
                    shareNoFrom = shareNoFrom + CashReceiveList[i].ShareNo;
                }
                else if (CashReceiveList[i].TransectionDetails == "SHARE HOLDER")
                {
                    shmShareAllotment[j].MemMemberRegistrationId = CashReceiveList[i].MemberRegistrationId;
                    shmShareAllotment[j].ShmShareTypeId = 3;
                    shmShareAllotment[j].ShareNo = CashReceiveList[i].ShareNo;
                    shmShareAllotment[j].ShareNoFrom = shareNoFrom + 1;
                    shmShareAllotment[j].ShareNoTo = shareNoFrom + CashReceiveList[i].ShareNo;
                    shmShareAllotment[j].SharePurchaseOn = Convert.ToDateTime(accountOpenEngDate);
                    shmShareAllotment[j].SharePurchaseOnBs = NepaliCalenderPicker.ShortNepaliDate;
                    shmShareAllotment[j].ShareFaceValue = shmShareTypeHolder.ShareFaceValue;
                    shmShareAllotment[j].SharePremium = shmShareTypeHolder.SharePremium;
                    shmShareAllotment[j].SharePurchaseAmount = CashReceiveList[i].Amount;
                    shmShareAllotment[j].Remarks = ASPxTxtRemarks.Text;
                    shmShareAllotment[j].CreatedBy = ucTO.UserId;
                    shmShareAllotment[j].CreatedOn = System.DateTime.Now;
                    shmShareAllotment[j].IsPosted = false;
                    shmShareAllotment[j].IsActive = true;
                    shmShareAllotment[j].IsReturned = false;
                    j++;
                    shareNoFrom = shareNoFrom + CashReceiveList[i].ShareNo;
                }
                else if (CashReceiveList[i].TransectionDetails == "LOAN SHARE")
                {
                    shmShareAllotment[j].MemMemberRegistrationId = CashReceiveList[i].MemberRegistrationId;
                    shmShareAllotment[j].ShmShareTypeId = 2;
                    shmShareAllotment[j].ShareNo = CashReceiveList[i].ShareNo;
                    shmShareAllotment[j].ShareNoFrom =0;
                    shmShareAllotment[j].ShareNoTo =0;
                    shmShareAllotment[j].SharePurchaseOn = Convert.ToDateTime(accountOpenEngDate);
                    shmShareAllotment[j].SharePurchaseOnBs = NepaliCalenderPicker.ShortNepaliDate;
                    shmShareAllotment[j].ShareFaceValue = shmShareTypeLoan.ShareFaceValue;
                    shmShareAllotment[j].SharePremium = shmShareTypeLoan.SharePremium;
                    shmShareAllotment[j].SharePurchaseAmount = CashReceiveList[i].Amount;
                    shmShareAllotment[j].Remarks = ASPxTxtRemarks.Text;
                    shmShareAllotment[j].CreatedBy = ucTO.UserId;
                    shmShareAllotment[j].CreatedOn = System.DateTime.Now;
                    shmShareAllotment[j].IsPosted = false;
                    shmShareAllotment[j].IsActive = true;
                    shmShareAllotment[j].IsReturned = false;
                    j++;
                }
            }
         
        }

        
            sycMasterCode[0].SycMasterCodeId = 2;
            sycMasterCode[0].MasterCodeValue = shareNoFrom;

            sycMasterCode[1].SycMasterCodeId = 4;
            sycMasterCode[1].MasterCodeValue = sycMasterCodeTransection.MasterCodeValue+1;
            //return acoTransaction;
            //return shmShareAllotment;
            //return sycMasterCode;
    }



while clicking on submit the error came of "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index' what is the problem.
the data is is not inserted on list acotranseciton
Posted
Updated 28-Dec-13 23:35pm
v5
Comments
Debug and see on which line it is throwing the Exception.

1 solution

it means that you are accessing an index value which is not present in collection.
before accessing a particular index, make sure that the index is available in that collection.

example:
consider this list: CashReceiveList , you are trying to access the list with index 5.
now you have check for index 5 is available in the collection. as

C#
if(   CashReceiveList.Count > 5 )
           { var somevariable = CashReceiveList[5]; }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900