Thursday, 31 January 2013

Treeview Data Retrive in Database and show in trieeview in window application


  void filltrv()
        {
            try
            {
                trvCategory.Nodes.Clear();
                var n = (from y in ss.GetInstance.GetAllMenus()
                         where y.Parent_Menu_ID == 0
                         select y).ToList();
                for (i = 0; i < n.Count; i++)
                {
                    TreeNode tn = new TreeNode();
                    tn.Tag = n[i].Menu_ID.ToString();
                    tn.Text = n[i].Menu_Name.ToString();
                    trvCategory.Nodes.Add(tn);
                }
                for (i = 0; i < trvCategory.Nodes.Count; i++)
                {
                    var nn = (from y in ss.GetInstance.GetAllMenus()
                              where y.Parent_Menu_ID == Convert.ToInt32(trvCategory.Nodes[i].Tag.ToString())
                              select y).ToList();
                    if (nn.Count > 0)
                    {
                        for (int j = 0; j < nn.Count; j++)
                        {
                            TreeNode tn1 = new TreeNode();
                            tn1.Tag = nn[j].Menu_ID.ToString();
                            tn1.Text = nn[j].Menu_Name.ToString();
                            trvCategory.Nodes[i].Nodes.Add(tn1);
                        }

                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
      private void trvCategory_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                int x=trvCategory.SelectedNode.Level;
                if (x == 0)
                {
                    TxtParentMenu.Text = trvCategory.SelectedNode.Text;
                    ParentMenuID = Convert.ToInt32(trvCategory.SelectedNode.Tag);
                }
                else
                {
                    TxtParentMenu.Text = trvCategory.SelectedNode.Parent.Text;
                    ParentMenuID = Convert.ToInt32(trvCategory.SelectedNode.Parent.Tag);
                }
               
               
                trvCategory.Visible = false;
                CmbSequence.Enabled = true;
                BindSequence();
            }
            catch (Exception ex)
            {
            }
        }
DataBase Design

Other City Add When user choose other in Combobox in WindoApplication


 void BindCity(int State_ID)
        {
            var objcity = from hhh in ERPManagement.GetInstance.GetAllCity()
                          where hhh.State_ID == State_ID
                          select hhh;

            List<ss> Cities = new List<ss>();
            ssdummy = new ss();
            dummy.City_Name = "Select";
            dummy.City_ID = 0;
            Cities.Add(dummy);
            foreach (ss City in objcity)
            {
                Cities.Add(City);
            }
            TAGGING_CountryStateCity dummy_ = new TAGGING_CountryStateCity();
            dummy_.City_Name = "Other";
            dummy_.City_ID = -1;
            Cities.Add(dummy_);
            cmbCity.DataSource = Cities;
            cmbCity.DisplayMember = "City_Name";
            cmbCity.ValueMember = "City_ID";
        }



 if (CourierId == 0)
            {
                ww ObjInsert = new ww ();
                ObjInsert.Courier_Code = TxtCourierCode.Text.Trim();
                if (TxtCourierName.Text != "")
                {
                    ObjInsert.Courier_Name = TxtCourierName.Text;
                }
                else
                {
                    MessageBox.Show("Courier name can't be blank.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);  
                    TxtCourierName.Focus();
                    return;
                }
                if (TxtContactPersonName.Text != "")
                {
                    ObjInsert.Contact_Person_Name = TxtContactPersonName.Text;
                }
                else
                {
                    MessageBox.Show("ContactPerson name can't be blank.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    TxtContactPersonName.Focus();
                    return;
                }
                if (TxtAddress.Text != "")
                {
                    ObjInsert.Address = TxtAddress.Text;
                }
                else
                {
                    MessageBox.Show("Address cannot be blank ", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    TxtAddress.Focus();
                    return;
                }
                ObjInsert.Mobile_No = TxtMobNo.Text;
                ObjInsert.Alternate_Mobile_No = TxtAlterNateMobNo.Text;

                ObjInsert.Phone_No = TxtPhoneNo.Text;
                ObjInsert.Fax_No = TxtFaxNo.Text;
                if (cmbCountry.SelectedIndex != 0)
                {
                    ObjInsert.Country_ID = Convert.ToInt32(cmbCountry.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a country. ", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
               
                    cmbCountry.Focus();
                    return;
                }
                if (cmbState.SelectedIndex != 0)
                {
                    ObjInsert.State_ID = Convert.ToInt32(cmbState.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a state.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);                
                    cmbState.Focus();
                    return;
                }
                if (cmbCity.SelectedIndex != 0)
                {
                    ObjInsert.City_ID = Convert.ToInt32(cmbCity.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a city.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);              
                    cmbCity.Focus();
                    return;
                }
                ObjInsert.Email_ID = TxtEmailId.Text;
                ObjInsert.Additional_Info1 = TxtAdditionalInfo1.Text;
                ObjInsert.Additional_Info2 = TxtAdditionalInfo2.Text;
                ObjInsert.Additional_Info3 = TxtAdditionalInfo3.Text;
                ObjInsert.City = TxtCityadd.Text.Trim();
                TxtCourierCode.Text=ERPManagement.GetInstance.InsertManageCourier(ObjInsert);
                MessageBox.Show("Data saved successfully.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Information);
               // tabControlItemType.SelectedIndex = 0;
                Reset();
            }
            else
            {
                Pos_ManageCourier ObjUpdate = new Pos_ManageCourier();
                ObjUpdate.Courier_Code = TxtCourierCode.Text;
                ObjUpdate.Courier_ID = CourierId;

                if (TxtCourierName.Text != "")
                {
                    ObjUpdate.Courier_Name = TxtCourierName.Text;
                }
                else
                {
                    MessageBox.Show("Courier name can't be blank.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);  
             
                    TxtCourierName.Focus();
                    return;
                }
                if (TxtContactPersonName.Text != "")
                {
                    ObjUpdate.Contact_Person_Name = TxtContactPersonName.Text;
                }
                else
                {
                    MessageBox.Show("Contact person name can't be blank. ", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);                  
                    TxtContactPersonName.Focus();
                    return;
                }
                if (TxtAddress.Text != "")
                {
                    ObjUpdate.Address = TxtAddress.Text;
                }
                else
                {
                    MessageBox.Show("Address can't be blank.", "ddd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    TxtAddress.Focus();
                    return;
                }
                ObjUpdate.Mobile_No = TxtMobNo.Text;
                ObjUpdate.Alternate_Mobile_No = TxtAlterNateMobNo.Text;

                ObjUpdate.Phone_No = TxtPhoneNo.Text;
                ObjUpdate.Fax_No = TxtFaxNo.Text;
                if (cmbCountry.SelectedIndex != 0)
                {
                    ObjUpdate.Country_ID = Convert.ToInt32(cmbCountry.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a country.", "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    cmbCountry.Focus();
                    return;
                }
                if (cmbState.SelectedIndex != 0)
                {
                    ObjUpdate.State_ID = Convert.ToInt32(cmbState.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a state.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);                  
                    cmbState.Focus();
                    return;
                }
                if (cmbCity.SelectedIndex != 0)
                {
                    ObjUpdate.City_ID = Convert.ToInt32(cmbCity.SelectedValue.ToString());
                }
                else
                {
                    MessageBox.Show("Select a city.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);                  
                    cmbCity.Focus();
                    return;
                }
                ObjUpdate.Email_ID = TxtEmailId.Text;
                ObjUpdate.Additional_Info1 = TxtAdditionalInfo1.Text;
                ObjUpdate.Additional_Info2 = TxtAdditionalInfo2.Text;
                ObjUpdate.Additional_Info3 = TxtAdditionalInfo3.Text;
                ObjUpdate.City = TxtCityadd.Text.Trim();
                ERPManagement.GetInstance.UpdateManageCourier(ObjUpdate);
                MessageBox.Show("Data updated successfully.", "dd", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                tabControlItemType.SelectedIndex = 0;
                TxtCityadd.Text = "";
                TxtCityadd.Visible = false;
            }
        }
StoreProcedure


ALTER PROCEDURE InsertManageCourier
(
@Courier_Name varchar(50),
@Contact_Person_Name varchar(50),
@Address varchar(max),
@City_ID INT,
@State_ID INT,
@Country_ID INT,
@Mobile_No varchar(20),
@Alternate_Mobile_No varchar(20),
@Phone_No varchar(20),
@Email_ID varchar(50),
@Fax_No varchar(50),
@Additional_Info1 varchar(max),
@Additional_Info2 varchar(max),
@Additional_Info3 varchar(max),
@CityName Varchar(50)=NULL,
@P_RET_VALUE    VARCHAR(50) OUTPUT
)
AS BEGIN
DECLARE @p_pcd VARCHAR(20)
SET @p_pcd=(SELECT RIGHT('000'+ CONVERT(VARCHAR(50),MAX(SUBSTRING(Courier_Code,1,4))+1),4)AS Courier_Code
            FROM Pos.MST_Courier)
SELECT @p_pcd=ISNULL(@p_pcd,'0001')
SET @P_RET_VALUE=@p_pcd


DECLARE @VAL INT
IF(@City_ID = -1)
BEGIN
INSERT into  City(State_ID,City_Name,Created_On,Is_Active,Is_Deleted)  VALUES(@State_ID,@CityName,GetDate(),1,0)
SET @VAL=SCOPE_IDENTITY()
INSERT INTO  MST_Courier
(Courier_Code,Courier_Name, Contact_Person_Name, Address,City_ID,State_ID,Country_ID,Mobile_No,Alternate_Mobile_No,Phone_No,Email_ID,Fax_No,Additional_Info1,Additional_Info2,Additional_Info3)
values(@P_RET_VALUE,@Courier_Name, @Contact_Person_Name,@Address,@VAL,@State_ID,@Country_ID,@Mobile_No,@Alternate_Mobile_No,@Phone_No,@Email_ID,@Fax_No,@Additional_Info1,@Additional_Info2,@Additional_Info3)

END
ELSE
BEGIN
INSERT INTO  MST_Courier
(Courier_Code,Courier_Name, Contact_Person_Name, Address,City_ID,State_ID,Country_ID,Mobile_No,Alternate_Mobile_No,Phone_No,Email_ID,Fax_No,Additional_Info1,Additional_Info2,Additional_Info3)
values(@P_RET_VALUE,@Courier_Name, @Contact_Person_Name,@Address,@City_ID,@State_ID,@Country_ID,@Mobile_No,@Alternate_Mobile_No,@Phone_No,@Email_ID,@Fax_No,@Additional_Info1,@Additional_Info2,@Additional_Info3)
END  

END
============================
Store Procedure Jeun Acchi @City_ID = -1 Taha front end re cs Page re Statically Set karajaichi ki je 
  dummy_.City_ID = -1;

Cristal Report In Dyanamically Method


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Swash.Objects;
using System.Data;
using System.Data.SqlClient;



  private void frmReportViewer_Load(object sender, EventArgs e)
        {

            TAGGING_CommonVariable objVar = new TAGGING_CommonVariable();
            objVar.servername = @"Satya\Linku";
            objVar.DatabaseName = "XXXXXX";
            objVar.username = "aaaa";
            objVar.password = "ddddd";

            if (reportFlag == 0)//IssueToQualityControl
            {
                crReportIssueToQC objCr = new crReportIssueToQC();
                CrystalDecisions.Shared.TableLogOnInfo tliCurrent = default(CrystalDecisions.Shared.TableLogOnInfo);
                try
                {
                    foreach (CrystalDecisions.CrystalReports.Engine.Table tbCurrent in objCr.Database.Tables)
                    {
                        tliCurrent = tbCurrent.LogOnInfo;
                        var _with1 = tliCurrent.ConnectionInfo;
                        _with1.ServerName = objVar.servername;
                        _with1.DatabaseName = objVar.DatabaseName;
                        _with1.UserID = objVar.username;
                        _with1.Password = objVar.password;
                        _with1.IntegratedSecurity = false;
                        tbCurrent.ApplyLogOnInfo(tliCurrent);
                    }

                    this.crystalReportViewerAll.ReportSource = objCr;
                    objCr.SetParameterValue(0, paramvalue);
                    //objCr.SetParameterValue(1, paramvalueId);
                    crystalReportViewerAll.Show();
                }
                catch
                {

                }
            }

Saturday, 11 August 2012

How to set a Local Variable in a store procedure and hold that value in Aspx page

Store procedure Pass a Local Varible which name is @out
ALTER PROCEDURE Ufms.[KC_DeleteGroup]
(
@Group_ID int,
@out int output

)
AS
BEGIN
    if EXISTS (SELECT Parent_Group_ID from Ufms.FMS_Groups WHERE Parent_Group_ID=@Group_ID)
     Select @out= 1
    ELSE
        BEGIN
        UPDATE Ufms.FMS_Groups SET Is_Deleted=1 Where Group_ID=@Group_ID
        END
END
==================================================
in Page behind Code in aspx page
====================================================
  public string DeleteGroups(int GroupID)
        {
            string MSG;
            SqlCommand deleteCommand = new SqlCommand("Ufms.KC_DeleteGroup");
            deleteCommand.CommandType = CommandType.StoredProcedure;
            deleteCommand.Parameters.Add(GetParameter("@Group_ID", SqlDbType.Int,                     Convert.ToInt32(GroupID)));
            deleteCommand.Parameters.Add(GetParameter("@OUT",SqlDbType.Int,null));
            deleteCommand.Parameters["@OUT"].Direction=ParameterDirection.Output;         
            ExecuteStoredProcedure(deleteCommand);         
            MSG= deleteCommand.Parameters["@OUT"].Value.ToString();         
            return MSG;
     
        }

Storeprocedure with Table Example


Table Name Groups

Table Name Ledgers

Table Name Ledger Opening Balances

Table Name Vouchers

Table Name Voucher Details


Table Name Financial Years
 
===============Store Procedure Example with Recursive  Store Procedure=========
====================This Store Procedure only Retrive ID and Check this Id is used in ParentGroup Id Or Not==================================================
For example -: in Leder Table the cash Ledger Id is 1 i will check that Ledger Id will used in parent Ledger Id or Not OR Retrive In cash Ledger Has child ledger or Not==========
 ALTER PROCEDURE [Ufms].[KC_SelectLedgersCash]
AS
BEGIN
WITH Ledgers AS (SELECT        l.Ledger_ID, l.Ledger_Name, l.Parent_Ledger_ID, lo.Dr_Amount, lo.Cr_Amount,lo.Financial_Year
                               FROM Ufms.FMS_Ledgers AS l INNER JOIN
                               Ufms.FMS_LedgerOpeningBalances AS lo ON l.Ledger_ID = lo.Ledger_ID
                               WHERE (l.Ledger_ID = 1 )
                   UNION ALL
                   SELECT C.Ledger_ID,c.Ledger_Name,c.Parent_Ledger_ID,f.Dr_Amount,f.Cr_Amount,f.Financial_Year
                   FROM Ledgers AS f INNER JOIN
                   Ufms.FMS_Ledgers AS c ON f.Ledger_ID=c.Parent_Ledger_ID
                   WHERE c.is_Active=1 and c.is_Deleted=0)
      SELECT        Ledger_ID, Ledger_Name, Parent_Ledger_ID,Dr_Amount,Cr_Amount,Financial_Year
     FROM            Ledgers AS Ledgers_1
END  
=======================Recursive Function ==================================
ALTER  procedure [Ufms].[KC_SelectLedgersCashBank]       

as
begin

WITH Ledgers AS (SELECT        Ledger_ID, Ledger_Name, Parent_Ledger_ID
                                        FROM            Ufms.FMS_Ledgers
                                        WHERE        (Ledger_ID = 1 or Ledger_ID=2)
                                        UNION ALL
                                        SELECT        c.Ledger_ID, c.Ledger_Name, c.Parent_Ledger_ID
                                        FROM            Ledgers AS f INNER JOIN
                                                                 Ufms.FMS_Ledgers AS c ON f.ledger_id = c.Parent_Ledger_ID where c.is_active=1 and c.is_deleted=0)
    SELECT        Ledger_ID, Ledger_Name, Parent_Ledger_ID
     FROM            Ledgers AS Ledgers_1
 end
 ==================================================================
--Author Satyabrata--11.08.2012
ALTER PROCEDURE Ufms.Kc_SelectReportLedgerBooks
@Fyear varchar(9)='2012-2013'
AS
BEGIN
     SELECT
     --From Ledger Table
        l.Ledger_ID,l.Ledger_Name,
        --From Ledger Opening Balance Table
        lob.Dr_Amount as LedgerOBDrAmount,lob.Cr_Amount LedgerOBcrAmount,
        lob.Financial_Year,lob.Is_Closed,
        --From Voucher Table
        v.Voucher_ID,v.Voucher_Date,convert(varchar(20),v.Voucher_Date,111) AS From_date,
        v.Voucher_Type,v.Voucher_No,v.Approved,
        --Voucher Details Table
        vd.Dr_Amount,vd.Cr_Amount,
        --Group Table
        g.Group_ID,g.Group_Name
        FROM
        Ufms.FMS_Ledgers AS l
        LEFT OUTER JOIN Ufms.FMS_LedgerOpeningBalances AS lob ON l.Ledger_ID=lob.Ledger_ID
        LEFT OUTER JOIN Ufms.FMS_VoucherDetails AS  vd ON l.Ledger_ID=vd.Ledger_ID
        LEFT OUTER JOIN Ufms.FMS_Vouchers AS v ON v.Voucher_ID=vd.Voucher_ID
        LEFT OUTER JOIN Ufms.FMS_Groups AS g ON l.Group_ID=g.Group_ID
        WHERE lob.Financial_Year=@Fyear
END
===============================================================
============This Store Procedure is show only cash details or cash child details Means if Cash Ledger has Child Ledger so create a view  that example is given below=============
That view is passe in this Storeprocedure because that view gives how much child ledger in a Parent Ledger
----------------------------------------------------------------------------------------------
ALTER PROCEDURE [Ufms].[KC_SelectCashDetails]
AS
BEGIN
SELECT   CONVERT(varchar(20),V.Voucher_Date,103) AS VoucherDate,CONVERT(varchar(20),V.Voucher_Date,111) AS From_Date,
          V.Voucher_No,V.Voucher_Type,V.Approved,VD.Voucher_Detail_ID,V.Voucher_ID,
          VD.Dr_Amount,VD.Cr_Amount, L.Ledger_Name, L.Ledger_ID
FROM       Ufms.FMS_VoucherDetails AS VD INNER JOIN
                 Ufms.FMS_Vouchers AS V ON VD.Voucher_ID=V.Voucher_ID INNER JOIN
                 Ufms.FMS_Ledgers AS L ON VD.Ledger_ID=L.Ledger_ID
                 WHERE L.Ledger_Id in (select ledger_id from Ufms.Fms_SelectLedgersCash_View) and  (V.Is_Active = 1) AND (V.Is_Deleted = 0) and (Vd.Is_Active = 1) AND (Vd.Is_Deleted = 0)and (l.Is_Active = 1) AND (l.Is_Deleted = 0)
END
=========================================================

 ===========This retrive how many child ledgers are in a parentLedger(cash) =================

 Create view  Fms_SelectLedgersCash_View
 as
   WITH Ledgers AS (SELECT        Ledger_ID
                               FROM Ufms.FMS_Ledgers
                               WHERE Ledger_ID = '1'
                              UNION ALL

                              SELECT C.Ledger_ID
                              FROM Ledgers AS f INNER JOIN
                              Ufms.FMS_Ledgers AS c ON f.Ledger_ID=c.Parent_Ledger_ID
                              WHERE c.is_Active=1 and c.is_Deleted=0)
         SELECT        Ledger_ID
     FROM            Ledgers AS Ledgers_1

===================================================================
Auto Generated Store Procedure
ALTER PROCEDURE [Ufms].[KC_InsertVouchers]
(
--@Voucher_No varchar(50),
@Voucher_Date datetime,
@Company_ID int,
@Voucher_Type varchar(50),
@Voucher_Amount decimal(18,2),
@Transaction_Type varchar(50),
@Description varchar(500),
--@Created_On datetime,
@Created_By int,
--@Modified_On datetime,
@Modified_By int,
@Out1 int output,
@Out2 varchar(30) output,
@Bank_Reconciliation_Date datetime =null,
-- Parameters for VoucherDetails
@DataTableVoucherDetails AS Ufms.VoucherDetailsType READONLY,
@Mode varchar(10)=null,
@vID int=null
)
   
AS
    BEGIN
    BEGIN TRANSACTION
    BEGIN TRY

    IF(@Mode!='Edit')
        BEGIN
    --Get the last Voucher No
        DECLARE @Voucher_No varchar(30)
        SELECT @Voucher_No=Voucher_No FROM Ufms.FMS_Vouchers WHERE Voucher_Type=@Voucher_Type
        DECLARE @Year int
        SELECT @Year=year(getdate())
        -- Generate the current Financial Year
        DECLARE @FYear varchar(10)
        IF MONTH(GETDATE())<3
            BEGIN
                SELECT @FYear=CONVERT(VARCHAR, @Year-1)+'-'+CONVERT(VARCHAR, @Year)
            END
        ELSE
            BEGIN
                SELECT @FYear=CONVERT(VARCHAR, @Year)+'-'+CONVERT(VARCHAR, @Year+1)
            END
        --Get the setup informations for voucher creation
                DECLARE @Prefix varchar(10)
                DECLARE @With_Financial_Year bit
                DECLARE @Auto_Number_Size int
                SELECT @Prefix=Prefix, @With_Financial_Year=With_Financial_Year, @Auto_Number_Size=Auto_Number_Size
                FROM Ufms.FMS_VoucherSetupDetails
                WHERE Voucher_Type=@Voucher_Type AND Company_ID=@Company_ID
                SELECT @Auto_Number_Size
                --Check the autonumber size
            --Set the auto number size
            DECLARE @i INT
            SET @i=1
            DECLARE @Size VARCHAR(10)
            SET @Size=''
            WHILE(@i<@Auto_Number_Size)
                BEGIN
                    SET @Size=@Size+'0'
                    SET @i=@i+1
                END
        --If It's a first voucher entry then generate the 1st voucher no. formats according to the setup
        IF @Voucher_No IS NULL
            BEGIN
                SET @Size=@Size+'1'
                --Define VoucherNo
                IF @With_Financial_Year=1
                    BEGIN
                        SELECT @Voucher_No=@Prefix+'/'+@Size+'/'+@FYear
                    END
                ELSE
                    BEGIN
                        SELECT @Voucher_No=@Prefix+'/'+@Size
                    END
            END
        ELSE
        -- If Voucher no is already generated
            BEGIN
                DECLARE @P1 VARCHAR(20)
                DECLARE @P2 VARCHAR(20)
                DECLARE @l int
                SET @l=LEN(@Prefix)
                SET @P1=Substring(@Voucher_No,1,@l)
                SET @P2=Substring(@Voucher_No,@l+2,@Auto_Number_Size)
                SET @P2=cast(@P2 as int)+1
                SET @Size=@Size+'0'
                SET @P2=RIGHT(@Size + RTRIM(@P2),@Auto_Number_Size)

                IF @With_Financial_Year=1
                    BEGIN
                        DECLARE @P3 VARCHAR(20)
                        SET @P3=Substring(@Voucher_No,@l+@Auto_Number_Size+3,9)
                        SET @Voucher_No=@P1+'/'+@P2+'/'+@P3
                        SET @Out2=@Voucher_No
                    END
                ELSE
                    BEGIN
                        SET @Voucher_No=@P1+'/'+@P2
                        SET @Out2=@Voucher_No
                    END
            END
        --Insert the record to Voucher Table
        INSERT INTO Ufms.FMS_Vouchers(
        Voucher_No,Voucher_Date,Company_ID,Voucher_Type,Voucher_Amount,
        Description,Bank_Reconciliation_Date,Created_On,Created_By,Modified_On,Modified_By)
        VALUES(
        @Voucher_No,@Voucher_Date,@Company_ID,@Voucher_Type,@Voucher_Amount,
        @Description,@Bank_Reconciliation_Date,GETDATE(),@Created_By,GETDATE(),@Modified_By)
        --SELECT @Company_ID,@Voucher_No,@Prefix,@With_Financial_Year,@Auto_Number_Size,@Size
        SET @Out1=SCOPE_IDENTITY()
        DECLARE @Voucher_ID int
        SET @Voucher_ID=SCOPE_IDENTITY()
        SET @Out2=@Voucher_No

        -- Insert Data into VoucherDetails
        INSERT INTO Ufms.FMS_VoucherDetails
        (Voucher_ID,Sl_No,Debit_Or_Credit,Ledger_ID,Dr_Amount,Cr_Amount,Transaction_Type,Cheque_Or_DD_No,Date,Bank_Name,Narration,
        Created_On,Created_By,Modified_On,Modified_By)
        SELECT
        @Voucher_ID,Sl_No,Debit_Or_Credit,Ledger_ID,Dr_Amount,Cr_Amount,Transaction_Type,Cheque_Or_DD_No,Date,Bank_Name,Narration,
        GETDATE(),@Created_By,GETDATE(),@Modified_By
        FROM @DataTableVoucherDetails

        END
    ELSE
        --For Edit
        BEGIN
        UPDATE Ufms.FMS_Vouchers
        SET
        Voucher_Date=@Voucher_Date,Company_ID=@Company_ID,Voucher_Type=@Voucher_Type,Voucher_Amount=@Voucher_Amount,
        Description=@Description,Modified_On=GETDATE(),Modified_By=@Modified_By
        WHERE
        Voucher_ID=@vID
        -- Delete Data from VoucherDetails
        DELETE FROM Ufms.FMS_VoucherDetails WHERE Voucher_ID=@vID
       
        -- Again Insert Data into VoucherDetails
        INSERT INTO Ufms.FMS_VoucherDetails
        (Voucher_ID,Sl_No,Debit_Or_Credit,Ledger_ID,Dr_Amount,Cr_Amount,Transaction_Type,Cheque_Or_DD_No,Date,Bank_Name,Narration,
        Created_On,Created_By,Modified_On,Modified_By)
        SELECT
        @vID,Sl_No,Debit_Or_Credit,Ledger_ID,Dr_Amount,Cr_Amount,Transaction_Type,Cheque_Or_DD_No,Date,Bank_Name,Narration,
        GETDATE(),@Created_By,GETDATE(),@Modified_By
        FROM @DataTableVoucherDetails

        END
        -- End of Insert Data into VoucherDetails
        --IF @@ERROR !=0
                --ROLLBACK TRAN
            --else
                --COMMIT TRAN
        COMMIT TRAN
        END TRY
        BEGIN CATCH
            ROLLBACK TRAN
        END CATCH
    END