如何在DAL中编写For循环以及如何在三层架构中的演示中调用它 [英] How to write For loop in DAL and how to call it in presentation in three tier architecture

查看:78
本文介绍了如何在DAL中编写For循环以及如何在三层架构中的演示中调用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在DAL中编写For循环以及如何在三层体系结构中的演示文稿中调用它

How to write For loop in DAL and how to call it in presentation in three tier architecture

推荐答案

您无法直接在类中调用循环而无需功能。您需要根据您的要求首先在函数中编写循环。



You cant directly call for loop in a class without having a function. You need to write your loop within a function first as per your requirement.

public class TestDAL
{
 public int YourFunction(int YourInput)
{
//Your For loop as you want

for (int i = 10 - 1; i >= 0; i--)
	{
	    // What you want to do within the for loop
	}
}
}





然后您需要将具有DAL类的项目引用到您的表示层。您可以右键单击参考文件夹并添加参考>>从解决方案中选择DAL项目



然后您完全将您的DAL项目推荐给UI。

在UI项目中转到您的班级。导入您已经提到的程序集。 (包括DAL类)

例如:



Then you need to refer the project having DAL Class to your Presentation Layer. You can right click the reference folder and add reference >> select the DAL project from solution

Then you have complete refer your DAL project to the UI.
Go to your class in UI project. import the assembly you referred already. (Included the DAL Class)
Eg:

using YourSolutionName.YourProjectName





然后你可以调用你的DAL类函数包含你的for循环。为此你需要首先创建DAL类的对象



例如:



Then You can call your DAL class function included your for loop.For that you need to create object of the DAL Class first

eg:

DALClass ObjDAL = new DALClass ();





然后你可以调用DAL的功能





Then You can call function of DAL

objDAL.YourFunction(int YourInput)





认为你可以理解这个过程。



Think you could understood the process.


实际上我必须在DAL中编写for循环并将它添加到Presentation层中的DataGridView。如何为此编写代码



这是示例代码



Actually I have to written for loop in DAL and it is added to DataGridView in Presentation layer.How to write code for this

Here is the sample code

for (int i = 0; i < Prodcode.Length; i++)
                    {
                        if (cn.State != ConnectionState.Open)
                            cn.Open();
                        cmd.Connection = cn;
                        string value = "";

                        cmd.CommandText = " select  A.[prod_code] [Code],A.[prod_desc] [Desc],invd_uom [UOM],A.invd_qty-A.invd_qty_sent-(select isnull(sum(invd_qty_sent),0) from invoice_details where prod_code='" + Prodcode[i] + "' and comp_id='" + cpnyid + "' and Link_inv_no=B.inv_no) as reserve,B.inv_no as Invoice  from invoice_details AS A" +
                                          " INNER JOIN invoice_master AS B ON A.inv_no=B.inv_no " +
                                          "  WHERE (A.invd_qty-A.invd_qty_sent)>0 AND a.invd_qty_reservePros='false' and A.comp_id='" + cpnyid + "'and B.cust_code= '" + cfs.singlequotconver(txt_Custcode.Text)
                                          + "' and prod_code ='" + Prodcode[i] + "' and b.inv_no='" + Trnno[i] + "'and invd_qty_reserveDone<>'true' and invd_id='" + IdS[i] + "'  union ";
                        cmd.CommandText += "select prod_code [Code],prod_desc [Desc],popr_uom [UOM],convert(decimal(18,0),popr_bqty)-(select isnull(sum(invd_qty_sent),0) from invoice_details where prod_code='" + Prodcode[i] + "' and comp_id='" + cpnyid + "' and Link_inv_no=product_open_balance_reserve.inv_no) as  [reserve],inv_no as Invoice " +
                            " from product_open_balance_reserve where comp_id='" + cpnyid + "' and cust_code='" + cfs.singlequotconver(txt_Custcode.Text) +
                            "' and prod_code ='" + Prodcode[i] + "' and inv_no='" + Trnno[i] + "' and popr_deleted=0 and popr_id='" + IdS[i] + "' ";
                        dr = cmd.ExecuteReader();
                        object[] obj1 = { "", "", "", Properties.Settings.Default.SendBalance.ToString() };
                        if (i == 0)
                        {
                            dataGridViewEx1.Rows.Add(obj1);
                        }
                        while (dr.Read())
                        {
                            object[] obj = { "", dr["Code"].ToString(), "", dr["Desc"].ToString(), "", "", dr["reserve"].ToString(), dr["UOM"].ToString(), "", "", dr["reserve"].ToString(), "", "", "", "", "", "", "", "", "", "", dr["Invoice"].ToString() };
                            dataGridViewEx1.Rows.Add(obj);
                        } dr.Close();

                    }


这篇关于如何在DAL中编写For循环以及如何在三层架构中的演示中调用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆