paul_vin Ответов: 1

Я хочу создать таблицу динамически с помощью string builder в C# и присвоить ей динамические значения


I want to create table dynamically using string builder in c# and assign dynamic values to It

Но вывод не показывает правильный формат

Что я уже пробовал:

if (dtJobWork1 != null)
           {
               for (int i = 0; i < dtJobWork1.Rows.Count; i++)
               {
                   if (dtJobWork1.Rows[i]["oType"] != null)
                   {
                       strOType = dtJobWork1.Rows[i]["oType"].ToString();
                   }

                   if (dtJobWork1.Rows[i]["OrderTypeAbbr"] != null)
                   {
                       StrOrderTypeAbbr = dtJobWork1.Rows[i]["OrderTypeAbbr"].ToString();
                   }
                   if (dtJobWork1.Rows[i]["OrderStatus"] != null)
                   {
                       StrOrderStatus = dtJobWork1.Rows[i]["OrderStatus"].ToString();
                       StrOrderStatus = "Test";
                   }
                   else
                   {
                       StrOrderStatus = "Test";
                   }
                   if (dtJobWork1.Rows[i]["OrderComments"] != null)
                   {
                       StrOrderComments = dtJobWork1.Rows[i]["OrderComments"].ToString();
                   }
                   if (dtJobWork1.Rows[i]["vNum"] != null)
                   {
                       StrvNum = dtJobWork1.Rows[i]["vNum"].ToString();
                   }

                   if (dtJobWork1.Rows[i]["SiteName"] != null)
                   {
                       StrSiteName = dtJobWork1.Rows[i]["SiteName"].ToString();
                   }

                   if (dtJobWork1.Rows[i]["SiteAddress"] != null)
                   {
                       StrSiteAddress = dtJobWork1.Rows[i]["SiteAddress"].ToString();
                   }

                   if (dtJobWork1.Rows[i]["CurrName"] != null)
                   {
                       StrCurrName = dtJobWork1.Rows[i]["CurrName"].ToString();
                   }
                   if (dtJobWork1.Rows[i]["OrderDate"] != null)
                   {
                       strODate = DateTime.Parse(dtJobWork1.Rows[i]["OrderDate"].ToString()).ToString("dd/MMM/yyyy");
                   }

                   if (dtJobWork1.Rows[i]["DueDate"] != null)
                   {
                       strDueDate = DateTime.Parse(dtJobWork1.Rows[i]["DueDate"].ToString()).ToString("dd/MMM/yyyy");
                   }
                   strTrCurr = dtJobWork1.Rows[i]["Currency"].ToString();

               }//for close


               #region -- Main table created
               strLblTbl.Append("<div id='divMain'>");

               if (strIsForex == "1")
               {
                   strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='width:800px;border:1px solid silver;font-family:Arial;font-size:12px;'>");
               }
               else
               {
                   strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='width:800px;border:1px solid silver;font-family:Arial;font-size:12px;'>");
               }
               #endregion

               #region -- table First Row
               strLblTbl.Append("<tr style='background-color:White;font-size:12px;font-weight:bold;'>");
               strLblTbl.Append("<td style='width:100%;height:30px;border-bottom:solid 1px silver;' valign='middle'>");

               strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='text-indent:5px;width:100%'>");
               strLblTbl.Append("<tr>");
               strLblTbl.Append("<td align = 'left' style='width:150px;'>" + strOID + "</td>");
               //if (strOType == "PO")
               //{
               strLblTbl.Append("<td style='width:50px;  ' align = 'left'>" + strOType + "</td>");

               //< div id = 'box' class='RounDiv2'></div>

               //}
               //if (strOType == "SO")
               //{
               //    strLblTbl.Append("<td style='width:50px;  ' align = 'left'><div id ='box' class='RounDiv3'></div>" + strOType + "</td>");
               //}
               //if (strIsForex == "1")
               //{
               //    decimal exchRate = 0;
               //    decimal.TryParse(strExchRATE, out exchRate);
               //    strLblTbl.Append("<td style='color:maroon;width:100px;' align = 'right'>" + strTrCurr + "</td>");
               //    //strLblTbl.Append("<td style='width:100px;' align = 'right'>" + Math.Abs(decimal.Parse(strExchRATE)).ToString("#,#0.0000#") + "  </td>");
               //    strLblTbl.Append("<td style='width:100px;' align = 'left'>@  " + GetTenDecimalValue(Math.Abs(exchRate)).ToString("#,#0.0000000000") + "  </td>");
               //}
               //else
               //{
               //    strLblTbl.Append("<td style='color:maroon;width:100px;' align = 'right'></td>");
               //    strLblTbl.Append("<td style='width:100px;' align = 'right'></td>");
               //}
               //if (strOstatus == "")
               //{
               //    strLblTbl.Append("<td style='width:200px;' align = 'right'></td>");
               //}
               //else
               //{
               strLblTbl.Append("<td style='width:200px;' align = 'right'>" + SiteName + " " + "[" + CurrencyName + "]" + "  </td>");
               //}

               strLblTbl.Append("</tr>");
               strLblTbl.Append("</table>");

               strLblTbl.Append("</td>");
               strLblTbl.Append("</tr>");
               #endregion


               #region -- table First Row
               //if (HdnSetting.Value.Trim() == "1")
               //{
               strLblTbl.Append("<tr style='background-color:White;font-size:12px;font-weight:bold;'>");
               strLblTbl.Append("<td style='width:100%;height:30px;border-bottom:solid 1px silver;' valign='middle'>");

               strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='text-indent:5px;'>");
               strLblTbl.Append("<tr>");
               strLblTbl.Append("<td align = 'left' style='width:150px;'>" + StrvNum + "</td>");
               strLblTbl.Append("<td style='width:50px;  ' align = 'left'><div id ='box'></div></td>");


               strLblTbl.Append("<td style='color:maroon;width:100px;' align = 'right'></td>");
               strLblTbl.Append("<td style='width:100px;' align = 'right'></td>");
               strLblTbl.Append("<td style='width:200px;' align = 'right'></td>");
               strLblTbl.Append("</tr>");
               strLblTbl.Append("</table>");

               strLblTbl.Append("</td>");
               strLblTbl.Append("</tr>");

               //}
               #endregion
               #region -- table First Row
               strLblTbl.Append("<tr style='background-color:White;font-size:12px;font-weight:bold;'>");
               strLblTbl.Append("<td style='width:100%;height:30px;border-bottom:solid 1px silver;' valign='middle'>");

               strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='text-indent:5px;width:100%'>");
               strLblTbl.Append("<tr>");
               strLblTbl.Append("<td align = 'left' style='width:150px;'>" + strODate + "</td>");
               strLblTbl.Append("<td style='width:50px;  ' align = 'left'>" + StrOrderStatus + "</td>");
               strLblTbl.Append("<td style='width:200px;' align = 'right'>" + strDueDate + "</td>");
               strLblTbl.Append("</tr>");
               strLblTbl.Append("</table>");
               strLblTbl.Append("</td>");
               strLblTbl.Append("</tr>");

               #endregion
               #region -- table First Row
               //if (HdnSetting.Value.Trim() == "1")
               //{
               strLblTbl.Append("<tr style='background-color:White;font-size:12px;font-weight:bold;'>");
               strLblTbl.Append("<td style='width:100%;height:30px;border-bottom:solid 1px silver;' valign='middle'>");

               strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='text-indent:5px;'>");
               strLblTbl.Append("<tr>");
               strLblTbl.Append("<td align = 'left' style='width:150px;'>" + StrOrderComments + "</td>");
               strLblTbl.Append("<td style='width:50px;  ' align = 'left'><div id ='box'></div></td>");


               strLblTbl.Append("<td style='color:maroon;width:100px;' align = 'right'></td>");
               strLblTbl.Append("<td style='width:100px;' align = 'right'></td>");
               strLblTbl.Append("<td style='width:200px;' align = 'right'></td>");
               strLblTbl.Append("</tr>");
               strLblTbl.Append("</table>");

               strLblTbl.Append("</td>");
               strLblTbl.Append("</tr>");

               //}
               #endregion
           }//if close dtJobWork1 table
           if (dtJobWork2 != null)
           {
               if (dtJobWork2.Rows.Count > 0)
               {
                   #region -- table 4th Row to show Item details Table
                   //  Item Details Table Header
                   strLblTbl.Append("<tr style='background-color:White;font-weight:bold;font-size:12px;'>");
                   strLblTbl.Append("<td style='border-top:solid 1px silver;'>");

                   strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='width:800px; text-indent:5px;'>");


                   if (strIsForex == "1")
                   {
                       strLblTbl.Append("<tr><td colspan='8'  style='padding-top:5px;padding-bottom:5px;' >Item Details</td></tr>");
                       strLblTbl.Append("<tr style='background-color:WhiteSmoke;'>");
                       strLblTbl.Append("<td style='height:18px;width:30px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>#</td>");

                       strLblTbl.Append("<td style='height:18px;width:130px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>Item</td>");

                       //strLblTbl.Append("<td style='height:18px;width:145px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>Item</td>");
                       strLblTbl.Append("<td style='height:18px;width:60px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>Item Code</td>");
                       if (countryCode.Equals("1"))
                       {
                           //strLblTbl.Append("<td style='height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; '>HSN Code  </td>");
                           strLblTbl.Append("<td style='height:18px;width:70px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; '>HSN Code  </td>");
                       }
                       else
                       {
                           //strLblTbl.Append("<td style='height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; '>GST Code  </td>");
                           strLblTbl.Append("<td style='height:18px;width:70px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; '>GST Code  </td>");

                       }


                       strLblTbl.Append("<td style='height:18px;width:55px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>UMO   </td>");


                       //strLblTbl.Append("<td style='height:18px;width:90px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>Quantity  </td>");

                       strLblTbl.Append("<td style='height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>Quantity  </td>");

                       //strLblTbl.Append("<td style='height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>Rate  </td>");

                       strLblTbl.Append("<td style='height:18px;width:70px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>Rate  </td>");

                       //strLblTbl.Append("<td style='height:18px;width:110px; border-bottom:solid 1px silver;  border-top:solid 1px silver;border-right:solid 1px silver; ' align = 'right'>Amount [" + strTrCurr + "]  </td>");
                       strLblTbl.Append("<td style='height:18px;width:100px; border-bottom:solid 1px silver;  border-top:solid 1px silver;border-right:solid 1px silver; ' align = 'right'>Amount [" + strTrCurr + "]  </td>");

                       //strLblTbl.Append("<td class='base' style='height:18px;width:110px; border-bottom:solid 1px silver;  border-top:solid 1px silver; ' align = 'right'>Amount [" + BaseCurr + "]  </td>");

                       strLblTbl.Append("<td class='base' style='height:18px;width:100px; border-bottom:solid 1px silver;  border-top:solid 1px silver; ' align = 'right'>Amount [" + BaseCurr + "]  </td>");
                   }
                   else
                   {
                       strLblTbl.Append("<tr><td colspan='7'  style='padding-top:5px;padding-bottom:5px;' >Item Details</td></tr>");
                       strLblTbl.Append("<tr style='background-color:WhiteSmoke;'>");
                       strLblTbl.Append("<td style='height:18px;width:30px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>#</td>");

                       //strLblTbl.Append("<td style='height:18px;width:205px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>Item</td>");
                       strLblTbl.Append("<td style='height:18px;width:180px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>Item</td>");

                       strLblTbl.Append("<td style='height:18px;width:60px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>Item Code</td>");

                       strLblTbl.Append("<td style='height:18px;width:55px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>UMO</td>");

                       if (countryCode.Equals("1"))
                       {
                           //strLblTbl.Append("<td style='height:18px;width:90px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver;text-indent:5px; ' >HSN Code  </td>");
                           strLblTbl.Append("<td style='height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver;text-indent:5px; ' >HSN Code  </td>");
                       }
                       else
                       {
                           //strLblTbl.Append("<td style='height:18px;width:90px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver;text-indent:5px; ' >GST Code  </td>");
                           strLblTbl.Append("<td style='height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver;text-indent:5px; ' >GST Code  </td>");

                       }
                       //strLblTbl.Append("<td style='height:18px;width:110px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>Quantity  </td>");
                       strLblTbl.Append("<td style='height:18px;width:100px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>Quantity  </td>");

                       //strLblTbl.Append("<td style='height:18px;width:110px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>Rate  </td>");
                       strLblTbl.Append("<td style='height:18px;width:100px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>Rate  </td>");

                       //strLblTbl.Append("<td style='height:18px;width:110px; border-bottom:solid 1px silver;  border-top:solid 1px silver; ' align = 'right'>Amount  </td>");
                       strLblTbl.Append("<td style='height:18px;width:100px; border-bottom:solid 1px silver;  border-top:solid 1px silver; ' align = 'right'>Amount  </td>");
                   }
                   //strLblTbl.Append("<td style='width:100px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>Action</td>");
                   strLblTbl.Append("</tr>");
                   strLblTbl.Append("</table>");

                   strLblTbl.Append("</td>");
                   strLblTbl.Append("</tr>");
                   //
                   #endregion

                   int strSrno = 0;
                   //Added by prince on 28/08/2016
                   string strHSNCode = string.Empty;
                   if (dtJobWork2 != null)
                   {
                       for (int i = 0; i < dtJobWork2.Rows.Count; i++)
                       {
                           if (dtJobWork2.Rows[i]["ItemId"] != null)
                           {
                               StrItemId = dtJobWork2.Rows[i]["ItemId"].ToString();
                           }
                           else
                           {
                               StrItemId = "0";
                           }

                           if (dtJobWork2.Rows[i]["ItemName"] != null)
                           {
                               StrItemName = dtJobWork2.Rows[i]["ItemName"].ToString();
                           }
                           else
                           {
                               StrItemName = "";
                           }
                           if (dtJobWork2.Rows[i]["ItemCode"] != null)
                           {
                               StrItemCode = dtJobWork2.Rows[i]["ItemCode"].ToString();
                           }
                           else
                           {
                               StrItemCode = "";
                           }
                           if (dtJobWork2.Rows[i]["HSNCode"] != null)
                           {
                               StrHSNCode = dtJobWork2.Rows[i]["HSNCode"].ToString();
                           }
                           else
                           {
                               StrHSNCode = "";
                           }

                           if (dtJobWork2.Rows[i]["UOM"] != null)
                           {
                               StrUOM = dtJobWork2.Rows[i]["UOM"].ToString();
                           }
                           else
                           {
                               StrUOM = "";
                           }

                           if (dtJobWork2.Rows[i]["Qty"] != null)
                           {
                               strQuantity = dtJobWork2.Rows[i]["Qty"].ToString();
                           }
                           else
                           {
                               strQuantity = "";
                           }

                           if (dtJobWork2.Rows[i]["Rate"] != null)
                           {
                               strRate = dtJobWork2.Rows[i]["Rate"].ToString();
                           }
                           else
                           {
                               strRate = "";
                           }

                           if (dtJobWork2.Rows[i]["Amount"] != null)
                           {
                               strTotalAmt = dtJobWork2.Rows[i]["Amount"].ToString();
                           }
                           else
                           {
                               strTotalAmt = "";
                           }


                           // Calculations

                           if (strQuantity.Trim() != "")
                           {
                               DecQty = Convert.ToDecimal(strQuantity);
                               DecSumQuantity = DecSumQuantity + DecQty;
                           }
                           else
                           {
                               DecSumQuantity = 0;
                           }


                           if (strRate.Trim() != "")
                           {
                               DecRate = decimal.Parse(strRate);
                           }
                           else
                           {
                               DecRate = 0;
                           }

                           if(strTotalAmt.Trim()!="")
                           {
                               DecAmount = decimal.Parse(strTotalAmt);
                               DecSumAmt = DecSumAmt + DecAmount;


                           }


                           strSrno = i + 1;


                           #region -- table 4th Row to show Item details Table
                           // Item Details Table Data
                           strLblTbl.Append("<tr style='background-color:White;font-size:12px;'>");
                           strLblTbl.Append("<td>");

                           strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='width:800px'>");
                           strLblTbl.Append("<tr>");
                           if (strIsForex == "1")
                           {
                               strLblTbl.Append("<td style= 'height:18px;width:30px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' align = 'left'>" + strSrno + "</td>");
                               //strLblTbl.Append("<td style=' height:18px;width:145px; border-bottom:solid 1px silver;  border-right:solid 1px silver;' align = 'left'><div style='margin-left:5px;'>" + StrItemName + "</div></td>");
                               strLblTbl.Append("<td style=' height:18px;width:130px; border-bottom:solid 1px silver;  border-right:solid 1px silver;' align = 'left'><div style='margin-left:5px;'>" + StrItemName + "</div></td>");

                               strLblTbl.Append("<td style=' height:18px;width:60px; border-bottom:solid 1px silver;  border-right:solid 1px silver; text-indent:5px;' align = 'left'>" + StrItemCode + "</td>");
                               if (countryCode.Equals("1"))
                               {
                                   //strLblTbl.Append("<td style=' height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; '>" + StrHSNCode + "  </td>");
                                   strLblTbl.Append("<td style=' height:18px;width:70px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; '>" + StrHSNCode + "  </td>");
                               }
                               else
                               {
                                   //strLblTbl.Append("<td style=' height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; '>" + strGST + "  </td>");
                                   strLblTbl.Append("<td style=' height:18px;width:70px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; '>" + strGST + "  </td>");

                               }

                               strLblTbl.Append("<td style=' height:18px;width:55px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; '>" + StrUOM + "  </td>");
                               //strLblTbl.Append("<td style='height:18px;width:55px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'right'>UMO   </td>");


                               //strLblTbl.Append("<td style=' height:18px;width:90px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px;' align = 'right'>" + currencyConverter(Math.Abs(DecQty)) + "  </td>");
                               strLblTbl.Append("<td style=' height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px;' align = 'right'>" + currencyConverter(Math.Abs(DecQty)) + "  </td>");
                               //strLblTbl.Append("<td style=' height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' align = 'right'>" + currencyConverter(GetTwoDecimalValue(Math.Abs(DecRate))) + "  </td>");
                               strLblTbl.Append("<td style=' height:18px;width:70px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' align = 'right'>" + currencyConverter(GetTwoDecimalValue(Math.Abs(DecRate))) + "  </td>");

                               strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;border-right:solid 1px silver;text-indent:5px;' align = 'right'>" + currencyConverter(Math.Abs(DecAmount)) + "  </td>");
                               //strLblTbl.Append("<td class='base' style=' height:18;width:110px; border-bottom:solid 1px silver;text-indent:5px;' align = 'right'>" + currencyConverter(Math.Abs(TotAmtB)) + "  </td>");
                           }
                           else
                           {
                               strLblTbl.Append("<td style= 'height:18px;width:30px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' align = 'left'>" + strSrno + "</td>");
                               strLblTbl.Append("<td style=' height:18px;width:180px; border-bottom:solid 1px silver;  border-right:solid 1px silver;' align = 'left'><div style='margin-left:5px;'>" + StrItemName + "</div></td>");
                               strLblTbl.Append("<td style=' height:18px;width:60px; border-bottom:solid 1px silver;  border-right:solid 1px silver; text-indent:5px;' align = 'left'>" + StrItemCode + "</td>");

                               strLblTbl.Append("<td style=' height:18px;width:55px; border-bottom:solid 1px silver;  border-right:solid 1px silver; text-indent:5px;' align = 'left'>" + StrUOM + "</td>");

                               //strLblTbl.Append("<td style='height:18px;width:55px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>UMO</td>");


                               if (countryCode.Equals("1"))
                               {
                                   //strLblTbl.Append("<td style=' height:18px;width:90px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' >" + StrHSNCode + "  </td>");
                                   strLblTbl.Append("<td style=' height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' >" + StrHSNCode + "  </td>");
                               }
                               else
                               {
                                   //strLblTbl.Append("<td style=' height:18px;width:90px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' >" + strGST + "  </td>");
                                   strLblTbl.Append("<td style=' height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' >" + strGST + "  </td>");

                               }
                               //strLblTbl.Append("<td style=' height:18px;width:110px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px;' align = 'right'>" + currencyConverter(Math.Abs(DecQty)) + "  </td>");
                               strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px;' align = 'right'>" + currencyConverter(Math.Abs(DecQty)) + "  </td>");

                               //strLblTbl.Append("<td style=' height:18px;width:110px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' align = 'right'>" + currencyConverter(GetTwoDecimalValue(Math.Abs(DecRate))) + "  </td>");

                               strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;  border-right:solid 1px silver;text-indent:5px; ' align = 'right'>" + currencyConverter(GetTwoDecimalValue(Math.Abs(DecRate))) + "  </td>");

                               //strLblTbl.Append("<td style=' height:18px;width:110px; border-bottom:solid 1px silver;text-indent:5px;' align = 'right'>" + currencyConverter(Math.Abs(DecAmount)) + "  </td>");
                               strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;text-indent:5px;' align = 'right'>" + currencyConverter(Math.Abs(DecAmount)) + "  </td>");

                           }

                           // strLblTbl.Append("<td style='width:100px; border-bottom:solid 1px silver;  border-right:solid 1px silver; border-top:solid 1px silver; ' align = 'left'>Action</td>");
                           strLblTbl.Append("</tr>");

                           strLblTbl.Append("</table>");

                           strLblTbl.Append("</td>");
                           strLblTbl.Append("</tr>");
                           #endregion
                       } //for close
                   }//if close

                   strIT = strSumTotalAmt;
                   strIB = strSumTotalAmtB;
                   #region -- table 4th Row to show Item details Table footer ROw Total

                   strLblTbl.Append("<tr style='background-color:White;font-size:12px;'>");
                   strLblTbl.Append("<td>");

                   strLblTbl.Append("<table cellspacing='0' cellpadding='0' style='width:800px; text-indent:5px;'>");
                   strLblTbl.Append("<tr style='background-color:WhiteSmoke;font-weight:Bold;'>");
                   if (strIsForex == "1")
                   {
                       strLblTbl.Append("<td style= 'height:18px;width:30px; border-bottom:solid 1px silver; border-right:solid 1px silver;  ' align = 'left'> </td>");


                       strLblTbl.Append("<td style=' height:18px;width:130px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'>Total</td>");

                       strLblTbl.Append("<td style=' height:18px;width:60px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'> </td>");


                       strLblTbl.Append("<td style=' height:18px;width:60px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'> </td>");

                       strLblTbl.Append("<td style=' height:18px;width:70px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'> </td>");

                       strLblTbl.Append("<td style=' height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver;' align = 'right'>  </td>");
                       strLblTbl.Append("<td style=' height:18px;width:70px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'>  </td>");
                       strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;border-right:solid 1px silver;' align = 'right'>" + currencyConverter(Math.Abs(DecSumAmt)) + "  </td>");
                       strLblTbl.Append("<td class='base' style=' height:18px;width:100px; border-bottom:solid 1px silver;' align = 'right'>" + currencyConverter(Math.Abs(strSumTotalAmtB)) + "  </td>");
                   }
                   else
                   {
                       strLblTbl.Append("<td style= 'height:18px;width:30px; border-bottom:solid 1px silver;border-right:solid 1px silver;   ' align = 'left'> </td>");
                       strLblTbl.Append("<td style=' height:18px;width:180px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'>Total</td>");
                       strLblTbl.Append("<td style=' height:18px;width:60px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'> </td>");

                       strLblTbl.Append("<td style=' height:18px;width:55px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'> </td>");

                       strLblTbl.Append("<td style=' height:18px;width:80px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'> </td>");

                       strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;' align = 'right'>" + currencyConverter(Math.Abs(DecSumQuantity)) + "  </td>");
                       //strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;  border-right:solid 1px silver;' align = 'right'>  </td>");
                       strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;  border-right:solid 1px silver; ' align = 'left'>  </td>");
                       strLblTbl.Append("<td style=' height:18px;width:100px; border-bottom:solid 1px silver;' align = 'right'>" + currencyConverter(Math.Abs(DecSumAmt)) + "  </td>");
                   }

                   strLblTbl.Append("</tr>");
                   strLblTbl.Append("</table>");

                   strLblTbl.Append("</td>");
                   strLblTbl.Append("</tr>");
                   #endregion
               }
           }

Richard MacCutchan

Итак, где-то в этих 700+ строках кода Вы хотите создать строку? Но вы хотите, чтобы мы угадали, где и из каких источников.

Patrice T

"Но вывод не показывает правильный формат"
Вы хотите помочь исправить код, но вы не говорите, что неправильно в фактическом выводе, что вы хотите как правильный вывод, и мы понятия не имеем о ваших данных.
Серьезно ?

1 Ответов

Рейтинг:
0

#realJSOP

Если бы это был я, Я бы создал класс, который представляет ваши данные строк и имеет свойства, определенные с соответствующими типами, которые соответствуют определениям столбцов в таблице. datatable:

public class MyItem
{
    public string OType { get; set; }
    ....
    public DateTime DueDate { get; set; }
}


Конструктор для этого класса будет выглядеть примерно так:
public MyItem(DataRow row)
{
    this.OType = this.GetColumnValue("oType", "UNK");
    ... 
    this.DueDate = this.GetColumnValue("DueDate", new DateTime(0));
}

public T GetColumnValue<t>(DataRow row, string colName, T defaultValue)
{
    object value = row[colName];
    T result = (value != null) ? (T)value : defaultValue;
    return result;
}

И добавьте свойство, которое возвращает строку таблицы html, уже отформатированную.
public string AsHtmlTableRow
{
    get
    {
        StringBuilder html = new StringBuilder();
        html.AppendLine("    <tr>");
        html.AppendFormat("        <td (with cell styles)>{0}</td>", this.OType).AppendLine();
        ...
        html.AppendFormat("        <td (with cell styles)>{0}</td>", this.DueDate.ToString("dd/MM/yyyy")).AppendLine();
        html.AppendLine("    </tr>");
        return html.ToString();
    }
}


В этот момент все, что вам нужно сделать, это

List<MyItem> items = new List<MyItem>();
foreach(DataRow row in dataTable.Rows)
{
    items.Add(new MyItem(row));
}

StringBuilder table = new StringBuilder();

table.AppendLine("<table (with table styles)>");

foreach(MyItem item in items)
{
    table.Append(item.AsHtmlDataRow);
}
table.AppendLine("</table>");


Имейте в виду, что приведенный выше код-это просто обобщенный псевдокод, поэтому вам нужно будет настроить его здесь и там и сформировать его в соответствии с вашими конкретными потребностями. Я не чувствую необходимости делать это сам, так как это ваш код, и я чувствую сильную потребность прямо сейчас сделать праведную свалку.

Кстати, небольшая гнида - создайте несколько классов стилей CSS, чтобы ваш html не был полон повторяющихся элементов CSS. Это просто разрушает html-код и затрудняет его чтение.


BillWoodruff

+5