Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

asp.net - Return a value in c# function

I have a function in .CS file. i want to return many values fetched in the function to .aspx.cs file(both files in the same project)

How to return a values from the below function(.CS file code is as follows):

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Collections;
using System.IO;


using iTextSharp.text.html.simpleparser;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;

/// <summary>
/// Summary description for Data
/// </summary>
public class Data
{
    public Data()
    {
        //
        // TODO: Add constructor logic here
        //



    }
    public void dat(AjaxControlToolkit.HTMLEditor.Editor Editor1,TextBox TextBox3, TextBox TextBox4, TextBox TextBox2, TextBox TextBox1, DropDownList DropDownList1, DropDownList DropDownList3, HiddenField HiddenField1, HiddenField HiddenField4)
{    
    String dbDate = DateTime.ParseExact(TextBox3.Text, "dd/mm/yyyy", null).ToString("yyyy-mm-dd");

        String respo1 = "";
        String respo2 = "";
        String editorcont1 = "";
        int res = 0;
        String sb = "";

        String petitioner = "";
        String petitioner1 = "";
        String resp = "";
        String resp1 = "";

        String respondants = "";
        String addr1 = "";
        String addr2 = "";


        var order = "";

        String nextdate = "";
        String nextdate1 = "**/**/****";
        String judge1 = "";
        String judge2 = "";
        String judge3 = "";
        String advocates = "";


        String a = DropDownList1.SelectedItem.Value;
        String b = DropDownList3.SelectedItem.Value.PadLeft(3, '0');
        String c = TextBox1.Text.PadLeft(5, '0').ToString();
        String d = TextBox2.Text.ToString();
        String digit = a + b + c + d;
        String jjj = "";


        try
        {
            OdbcConnection casetype = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=10.155.160.130;Database=testcase;User=root;Password=;Option=3;");
            casetype.Open();

            String petresquery1 = "select fil_no from testcase.main where reg_no =? OR fil_no=?";
            OdbcCommand petrescmd1 = new OdbcCommand(petresquery1, casetype);
            petrescmd1.Parameters.AddWithValue("?", digit);
            petrescmd1.Parameters.AddWithValue("?", digit);
            OdbcDataReader respetMyReader1 = petrescmd1.ExecuteReader();

            while (respetMyReader1.Read())
            {
                String fil_no = respetMyReader1["fil_no"].ToString();
                HiddenField4.Value = fil_no;
                //Response.Write(HiddenField4.Value);
            }


            string showmodifquery = "select notice from notice_aspx where fil_no=?";

            OdbcCommand showmodifcmd = new OdbcCommand(showmodifquery, casetype);

            showmodifcmd.Parameters.AddWithValue("?", HiddenField4.Value);
            OdbcDataReader showmodifMyReader = showmodifcmd.ExecuteReader();

            if (showmodifMyReader.Read())
            {
                String showmodif1 = showmodifMyReader["notice"].ToString();

               Editor1.Content = showmodif1;
            }
            else
            {
                //************to get case type     
                string casetypequery = "select casename from casetype where skey=?";
                //************to get pet  res
                string petresquery = "select pet_name,res_name from testcase.main where reg_no =? OR fil_no=?";
                //*******to get respondants 
                string respoquery = "SELECT sr_no,partyname,addr1,addr2 FROM testcase.party where fil_no=? and pet_res='R'order by sr_no,party_lh,party_lh2,party_lh3,party_lh4,party_lh5";
                //*******to get order
                string ordequery = "select orde from testcase.orddetpabak where fil_no=? and orderdate=?";
                //*********to get next date
                string nextdatequery = "SELECT next_dt FROM testcase.heardt where fil_no=? and next_dt>?;";
                //*********to get jud1
                string jud1query = "select jname from testcase.orddetpabak,testcase.judge where orddetpabak.jud1 = judge.jcode and fil_no=? and orderdate=?;";
                //*********to get jud2
                string jud2query = "select jname from testcase.orddetpabak,testcase.judge where orddetpabak.jud2 = judge.jcode and fil_no=? and orderdate=?;";
                //*********to get jud3
                string jud3query = "select jname from testcase.orddetpabak,testcase.judge where orddetpabak.jud3 = judge.jcode and fil_no=? and orderdate=?;";
                //*********to get advocates
                string advquery = "SELECT adv FROM testcase.orddetpabak where fil_no=? and orderdate=?";



                //************to get case type 
                OdbcCommand casetypecmd = new OdbcCommand(casetypequery, casetype);
                String casetypefromdropdown = DropDownList3.SelectedItem.ToString();
                casetypecmd.Parameters.AddWithValue("?", casetypefromdropdown);
                using (OdbcDataReader casetypeMyReader = casetypecmd.ExecuteReader())
                {
                    while (casetypeMyReader.Read())
                    {
                        String casename = casetypeMyReader["casename"].ToString();
                        HiddenField1.Value = casename;
                    }
                }

                //************to get pet  res
                OdbcCommand petrescmd = new OdbcCommand(petresquery, casetype);
                petrescmd.Parameters.AddWithValue("?", digit);
                petrescmd.Parameters.AddWithValue("?", digit);
                using (OdbcDataReader respetMyReader = petrescmd.ExecuteReader())
                {
                    while (respetMyReader.Read())
                    {
                        petitioner1 = respetMyReader["pet_name"].ToString();

                        //petitioner1 = petitioner.Substring(0, 1) + petitioner.Substring(1).ToLower();
                        resp1 = respetMyReader["res_name"].ToString();
                        //resp1 = resp.Substring(0, 1) + resp.Substring(1).ToLower();

                        //String fil_no = respetMyReader["fil_no"].ToString();
                        //HiddenField4.Value = fil_no;
                        ////Response.Write(HiddenField4.Value);
                      // return petitioner1;
                    }
                    if (petitioner1 == "")
                    {
                        HttpContext.Current.Response.Write("<b><font color='red'>Wrong Entry!!!");
                    }
                }


                //*******to get respondants

                String respo = HiddenField4.Value;
                OdbcCommand respocmd = new OdbcCommand(respoquery, casetype);
                respocmd.Parameters.AddWithValue("?", respo);
                using (OdbcDataReader respoMyReader = respocmd.ExecuteReader())
                {
                    while (respoMyReader.Read())
                    {
                        respo1 = respoMyReader["sr_no"].ToString();
                        respo2 = respoMyReader["partyname"].ToString();
                        addr1 = respoMyReader["addr1"].ToString();
                        addr2 = respoMyReader["addr2"].ToString();
                        res = Convert.ToInt32(respo1);
                        //Response.Write(res);
                        //Response.Write(respo2);

                        //editorcont1 = "<table><tr><td width='10'>" + res + "</td><td>"+"<P align= 'left'>"+  respo2 +"</P></td>"+"</br>";

                        ////HiddenField7.Value = editorcont1;
                        //asd(editorcont1);

                        //respondants = respo2.Substring(0, 1) + respo2.Substring(1).ToLower();
                        //addr1 = addr1.Substring(0, 1) + addr1.Substring(1).ToLower();
                        //addr2 = addr2.Substring(0, 1) + addr2.Substring(1).ToLower();
                        editorcont1 = res + ")&nbsp;&nbsp;" + respo2 + "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + addr1 + "&nbsp;&nbsp;" + addr2 + "<br/>";
                        sb = sb + editorcont1;
                    }
                }

                //*******to get order
                OdbcCommand ordecmd = new OdbcCommand(ordequery, casetype);
                ordecmd.Parameters.AddWithValue("?", HiddenField4.Value);
                ordecmd.Parameters.AddWithValue("?", dbDate);
                using (OdbcDataReader ordeMyReader = ordecmd.ExecuteReader())
                {
                    while (ordeMyReader.Read())
                    {
                        order = ordeMyReader["orde"].ToString();
                    }

                }
                //*******to get nextdate
                OdbcCommand nextdatecmd = new OdbcCommand(nextdatequery, casetype);
                nextdatecmd.Parameters.AddWithValue("?", HiddenField4.Value);
                nextdatecmd.Parameters.AddWithValue("?", dbDate);
                using (OdbcDataReader nextdateMyReader = nextdatecmd.ExecuteReader())
                {
                    while (nextdateMyReader.Read())
                    {
                        nextdate = nextdateMyReader["next_dt"].ToString();

                    }
                    nextdate1 = Convert.ToDateTime(nextdate).ToString("dd/MM/yyyy");


                }

                //*********to get jud1
                OdbcCommand jud1cmd = new OdbcCommand(jud1query, casetype);
                jud1cmd.Parameters.AddWithValue("?", HiddenField4.Value);
                jud1cmd.Parameters.AddWithValue("?", dbDate);
                using (OdbcDataReader jud1MyReader = jud1cmd.ExecuteReader())
                {
                    while (jud1MyReader.Read())
                    {
                        judge1 = jud1MyReader["jname"].ToString();
                        jjj = "J";
                    }
                }


                //*********to get jud2
                OdbcCommand jud2cmd = new OdbcCommand(jud2query, casetype);
                jud2cmd.Parameters.AddWithValue("?", HiddenField4.Value);
                jud2cmd.Parameters.AddWithValue("?", dbDate);
                using (OdbcDataReader jud2MyReader = jud2cmd.ExecuteReader())
                {
                    while (jud2MyReader.Read())
                    {
                        judge2 = jud2MyReader["jname"].ToString();
                        jjj = "JJ";
                    }
                }


                //*********to get jud3
                OdbcCommand jud3cmd = new OdbcCommand(jud3query, casetype);
                jud3cmd.Parameters.AddWithValue("?", HiddenField4.Value);
                jud3cmd.Parameters.AddWithValue("?", dbDate);
                using (OdbcDataReader jud3MyReader = jud3cmd.ExecuteReader())
                {
                    while (jud3MyReader.Read())
                    {
                        judge3 = jud3MyReader["jname"].ToString();
                        jjj = "JJJ";
                    }
                }
                //*******to get advocates
                OdbcCommand advcmd = new OdbcCommand(advquery, casetype);
                advcmd.Parameters.AddWithValue("?", HiddenField4.V

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to return more than one value from a method, you need to create a class to do so.

For example:

public class Product
{
   int Id { get; set;} 
   string Name { get; set;} 
   double Value { get; set;}
}

And then when you want to return a Product from your method:

public Product GetProduct(string Id) 
{
   Product product; 
   // load product here
   return product; 
} 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...