public ActionResult ChequeRealize(FormCollection form)
        {
            int ChekId = (string.IsNullOrEmpty(form["ChekId"])) ? 0 : Convert.ToInt32(form["ChekId"]);

            try
            {
                string IndetityVals = string.Empty;
                int    InvoiceCount = (string.IsNullOrEmpty(form["InvoiceCount"])) ? 0 : Convert.ToInt32(form["InvoiceCount"]);
                int    AgentId      = (string.IsNullOrEmpty(form["AgentId"])) ? 0 : Convert.ToInt32(form["AgentId"]);
                AgentBulkPaymentChequePayment Obj = new AgentBulkPaymentChequePayment();
                Obj.Amount        = (string.IsNullOrEmpty(form["Amount"])) ? 0 : Convert.ToDouble(form["Amount"]);
                Obj.Notes         = (string.IsNullOrEmpty(form["Notes"])) ? String.Format("{0}", string.Empty) : String.Format("{0}", Convert.ToString(form["Notes"]));
                Obj.LedgerDate    = (string.IsNullOrEmpty(form["LedgerDate"])) ? string.Empty : Convert.ToString(form["LedgerDate"]);
                Obj.UserId        = User.Identity.GetUserId();
                Obj.AgentId       = AgentId;
                Obj.BankAccountId = (string.IsNullOrEmpty(form["BankAccountIdBP"])) ? 0 : Convert.ToInt32(form["BankAccountIdBP"]);
                Obj.BankDate      = (string.IsNullOrEmpty(form["LedgerDate"])) ? string.Empty : Convert.ToString(form["LedgerDate"]);
                Obj.ChekId        = ChekId;
                IndetityVals      = new AgentDA().AgentBulkPaymentChequePayment(Obj);
                string[] SplitVals = IndetityVals.Split(',');
                if (SplitVals.Length == 3 && Convert.ToInt32(SplitVals[0]) > 0)
                {
                    for (int i = 1; i <= InvoiceCount; i++)
                    {
                        BulkPaymentAgentCashInvPaymentInvLog lObj = new BulkPaymentAgentCashInvPaymentInvLog();
                        lObj.AgentId             = AgentId;
                        lObj.AgentLedgerId       = Convert.ToInt32(SplitVals[1]);
                        lObj.Amount              = (string.IsNullOrEmpty(form["PaidAmount" + i])) ? 0 : Convert.ToDouble(form["PaidAmount" + i]);
                        lObj.GeneralLedgerId     = Convert.ToInt32(SplitVals[0]);
                        lObj.InvoiceId           = (string.IsNullOrEmpty(form["InvoiceId" + i])) ? 0 : Convert.ToInt32(form["InvoiceId" + i]);
                        lObj.Notes               = (string.IsNullOrEmpty(form["Notes"])) ? String.Format("{0}", string.Empty) : String.Format("{0}", Convert.ToString(form["Notes"]));
                        lObj.UserID              = User.Identity.GetUserId();
                        lObj.LedgerDate          = (string.IsNullOrEmpty(form["LedgerDate"])) ? string.Empty : Convert.ToString(form["LedgerDate"]);
                        lObj.BankAccountLedgerId = Convert.ToInt32(SplitVals[2]);
                        if (lObj.Amount > 0)
                        {
                            new AgentDA().BulkPaymentAgentCashVoucherInvoicePaymentInvoiceLog(lObj);
                        }
                    }
                }
                return(RedirectToAction("InvoicePayment", "Agent"));
            }
            catch (Exception ec)
            {
                return(RedirectToAction("InvoicePayment", "Agent"));
            }
        }
        public string AgentBulkPaymentChequePayment(AgentBulkPaymentChequePayment model)
        {
            try
            {
                string status = string.Empty;
                using (SqlConnection connection = DataAccess.CreateConnection())
                {
                    SqlCommand command = DataAccess.CreateCommand(connection);

                    DataAccess.CreateStoredprocedure(command, "InsertBulkPaymentAgentChequePayment_SP");
                    DataAccess.AddInParameter(command, "@Amount", SqlDbType.Float, model.Amount);
                    DataAccess.AddInParameter(command, "@Notes", SqlDbType.VarChar, model.Notes);
                    DataAccess.AddInParameter(command, "@LedgerDate", SqlDbType.VarChar, model.LedgerDate);
                    DataAccess.AddInParameter(command, "@UserId", SqlDbType.VarChar, model.UserId);
                    DataAccess.AddInParameter(command, "@AgentId", SqlDbType.Int, model.AgentId);
                    DataAccess.AddInParameter(command, "@BankAccountId", SqlDbType.Int, model.BankAccountId);
                    DataAccess.AddInParameter(command, "@BankDate", SqlDbType.VarChar, model.BankDate);
                    DataAccess.AddInParameter(command, "@ChekId", SqlDbType.Int, model.ChekId);

                    SqlDataReader reader = DataAccess.ExecuteReader(command);
                    if (reader != null)
                    {
                        while (reader.Read())
                        {
                            status = reader["IndentityVals"] is DBNull ? string.Empty : Convert.ToString(reader["IndentityVals"]);
                        }
                    }
                    reader.Close();
                    return(status);
                }
            }
            catch (Exception ex)
            {
                return(string.Empty);
            }
        }