当前位置: 首页>>代码示例>>C#>>正文


C# DataRow.Count方法代码示例

本文整理汇总了C#中DataRow.Count方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.Count方法的具体用法?C# DataRow.Count怎么用?C# DataRow.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataRow的用法示例。


在下文中一共展示了DataRow.Count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSeatLayout

    public static String GetSeatLayout(DataTable dtMain, String seatType, String travelOperator)
    {
        StringBuilder sbSeatLayout = new StringBuilder();
        StringBuilder sbSeatLayoutSleeper = new StringBuilder();

        DataTable dtUpper = dtMain.Clone();
        dtUpper.TableName = "Upper";

        DataTable dtLower = dtMain.Clone();
        dtLower.TableName = "Lower";

        DataSet dsSleeper = new DataSet();
        dtMain.TableName = "Main";

        DataSet dss = dtMain.DataSet;
        if (dss == null) { dsSleeper.Tables.Add(dtMain); }
        else { dtMain.DataSet.Tables.Clear(); dsSleeper.Tables.Add(dtMain); }

        //travelOperator.ToLower().Contains("svr") && travelOperator.ToLower().Contains("tours") && travelOperator.ToLower().Contains("travels") &&
        if (seatType.ToString().ToLower().Contains("sleeper") && !seatType.ToString().ToLower().Contains("semi"))
        {
            foreach (DataRow item in dtMain.Rows)
            {
                if (item["Seat"].ToString().ToUpper().Contains("U"))
                {
                    dtUpper.ImportRow(item);
                }
                if (item["Seat"].ToString().ToUpper().Contains("L"))
                {
                    dtLower.ImportRow(item);
                }
            }
            if (dtLower.Rows.Count >= 0 && dtUpper.Rows.Count >= 0)
            {
                dsSleeper.Tables.Clear();
                dsSleeper.Tables.Add(dtUpper);
                dsSleeper.Tables.Add(dtLower);
            }
        }
        try
        {
            if (dsSleeper.Tables.Count != 0)
            {
                for (int tbl = 0; tbl < dsSleeper.Tables.Count; tbl++)
                {
                    dtMain = dsSleeper.Tables[tbl];

                    if (dtMain.Rows.Count > 0)
                    {
                        #region Code to convert "Row" & "Column" columns to integer datatype

                        //create a copy of main table
                        DataTable dt = dtMain.Clone();
                        //set column datatypes for int values
                        dt.Columns["row"].DataType = Type.GetType("System.Int16");
                        dt.Columns["column"].DataType = Type.GetType("System.Int16");
                        //dt.Columns["zIndex"].DataType = Type.GetType("System.Int16");

                        DataRow[] drArray1 = null;
                        //DataRow[] drArray1 = dtMain.Select(String.Empty, "row, column ASC");

                        if (dtMain.Rows[0][0].ToString() == "Bit" || dtMain.Rows[0][0].ToString() == "Tig")
                        {
                            drArray1 = dtMain.Select(String.Empty, "Row DESC, Column ASC");
                        }
                        else { drArray1 = dtMain.Select(String.Empty, "Row, Column ASC"); }

                        if (drArray1.Length > 0)
                        {
                            foreach (DataRow dr in drArray1)
                                dt.ImportRow(dr);
                        }

                        dt.AcceptChanges();

                        #endregion

                        var zIndexCount = "1".ToList();

                        //var zIndexCount = (from dr in dt.AsEnumerable() select dr["zIndex"]).Distinct().ToList();

                        var RowCount = (from dr in dt.AsEnumerable() select dr["row"]).Distinct().ToList();

                        var ColumnCount = (from dr in dt.AsEnumerable() select dr["column"]).Distinct().ToList();

                        //Used in exceptional cases where a bus has both seats and sleeper coaches
                        //int maxLength = Convert.ToInt32(dt.Compute("max(Length)", string.Empty));
                        //int maxLength = (from dr in dt.AsEnumerable() select dr["length"]).Distinct().Count();
                        //int maxWidth = (from dr in dt.AsEnumerable() select dr["width"]).Distinct().Count();
                        int maxLength = 1;
                        int maxWidth = 1;

                        String strSeatType = String.Empty;
                        String strSeatCssSuffix = String.Empty;

                        if (zIndexCount.Count > 1)
                            sbSeatLayout.Append("<table align=\"center\"><tr><td colspan=\"2\">");
                        else
                            sbSeatLayout.Append("<table align=\"center\" style=\"border: 1px solid #D3D3D3; border-radius: 4px; padding: 3px; margin: 3px; \"><tr><td colspan=\"2\">");

//.........这里部分代码省略.........
开发者ID:srisai339,项目名称:LoveJourney_Working,代码行数:101,代码来源:ShowTrips.aspx.cs

示例2: GetSeatLayout

    private String GetSeatLayout(DataTable dtMain)
    {
        StringBuilder sbSeatLayout = new StringBuilder();
        StringBuilder sbSeatLayoutSleeper = new StringBuilder();

        try
        {
            if (dtMain.Rows.Count > 0)
            {

                Class1 obj = new Class1();
                obj.ScreenInd = Master123.GetMarkup;
                DataSet ds = obj.fnGetData();

                DataRow drSpecialPrice = ds.Tables[0].Rows[0];

                #region Code to convert "Row" & "Column" columns to integer datatype

                //create a copy of main table
                DataTable dt = dtMain.Clone();
                //set column datatypes for int values
                dt.Columns["row"].DataType = Type.GetType("System.Int16");
                dt.Columns["column"].DataType = Type.GetType("System.Int16");
                dt.Columns["zIndex"].DataType = Type.GetType("System.Int16");

                DataRow[] drArray1 = dtMain.Select(String.Empty, "row, column ASC, zIndex DESC");
                if (drArray1.Length > 0)
                {
                    foreach (DataRow dr in drArray1)
                        dt.ImportRow(dr);
                }

                dt.AcceptChanges();

                #endregion

                var zIndexCount = (from dr in dt.AsEnumerable() select dr["zIndex"]).Distinct().ToList();

                var RowCount = (from dr in dt.AsEnumerable() select dr["row"]).Distinct().ToList();

                var ColumnCount = (from dr in dt.AsEnumerable() select dr["column"]).Distinct().ToList();

                //Used in exceptional cases where a bus has both seats and sleeper coaches
                //int maxLength = Convert.ToInt32(dt.Compute("max(Length)", string.Empty));
                int maxLength = (from dr in dt.AsEnumerable() select dr["length"]).Distinct().Count();
                int maxWidth = (from dr in dt.AsEnumerable() select dr["width"]).Distinct().Count();

                String strSeatType = String.Empty;
                String strSeatCssSuffix = String.Empty;

                if (zIndexCount.Count > 1)
                    sbSeatLayout.Append("<table  align=\"center\"  width=\"99%\"><tr><td colspan=\"2\"  >");

                else
                    sbSeatLayout.Append("<table  align=\"center\" style=\"border: 1px solid #D3D3D3; border-radius: 4px; padding: 0px; margin: 0px; \"><tr><td  style=\"float:left;\"><span style=\"float:left;\" class=\"steering\"></span></td><td>");//colspan=\"2\"
                foreach (Int16 index in zIndexCount)
                {
                    if (zIndexCount.Count > 1)
                    {
                        //div tag is added to show border with same size for upper and lower decks
                        sbSeatLayout.Append("<div style=\"border: 1px solid #D3D3D3; border-radius: 4px; padding: 3px; margin: 3px;width:425px; \">");
                        //add steering image only once
                        //if (zIndexCount.IndexOf(index) > 0)
                        //    sbSeatLayout.Append("<span class=\"steering\" style=\"margin-top: 2px; float: left; \"/>");

                        if (index == 0)
                            sbSeatLayout.Append("<span class=\"lowerLabel\" style=\"margin-top: 1px; float: left; width:29; height:29; \"></span>");//class=\"lowerLabel\Lower\&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lower"
                        else
                            sbSeatLayout.Append("<span class=\"upperLabel\" style=\"margin-top: 1px; float: left; width:29; height:29; \"></span>");//class=\"upperLabel\Upper"
                        sbSeatLayout.Append("<table>");

                    }
                    else
                        sbSeatLayout.Append("<div><span  style=\"margin-top: 2px; float: left; \"/><table>"); //class=\"steering\"

                    Int16 GangwayRow = 0;
                    foreach (Int16 row in RowCount)
                    {
                        #region Gangway

                        if (GangwayRow != row)
                        {
                            //check if bus has different seat layouts. If so, do not float seats right
                            if (maxLength == 2 && maxWidth == 2)
                                sbSeatLayout.Append("<tr><td>");
                            else
                                sbSeatLayout.Append("<tr><td style=\"float: right\">");

                            sbSeatLayout.Append("<ul class=\"seat_map\">");

                            sbSeatLayout.Append("<li>&nbsp;</li>");
                            sbSeatLayout.Append("</ul>");
                            sbSeatLayout.Append("</<td></tr>");
                            GangwayRow++;
                        }
                        GangwayRow++;

                        #endregion

                        #region Create datarow array
//.........这里部分代码省略.........
开发者ID:srisai339,项目名称:LoveJourney_Working,代码行数:101,代码来源:BusService.cs


注:本文中的DataRow.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。