protected void DataContent() { string database = Session["DatabaseName"].ToString(); string vsSql = ""; //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); string ListStr1 = @"<tr> <td class=""auto-style103""> <a href=""{4}"" target=_blank ><img src="" ../img/Edit.png"" alt=""檢視單價分析"" style=""Width:27px"" ></a> </td><td class=""auto-style105""> <asp:Label ID=""Label738"" runat=""server"" Font-Names=""微軟正黑體"" Font-Size=""Medium"" >{2}</asp:Label> </td><td class=""auto-style105""> <asp:Label ID=""Label736"" runat=""server"" Font-Size=""Medium"" Height=""25px"">{0}</asp:Label> </td><td class=""auto-style103""> <asp:Label ID=""Label737"" runat=""server"" Font-Size=""Medium"" Height=""25px"" Width=""50px"">{1}</asp:Label> </td> <td class=""auto-style106"">{3}</td>"; string selectedValue = ""; StringBuilder tmpStr1 = new StringBuilder(); var totalcount1 = CheckBoxList1.Items.Cast <ListItem>().Where(item => item.Selected).Count(); //CheckBoxList1被選擇之數量(欄位選擇) var totalcount2 = CheckBoxList2.Items.Cast <ListItem>().Where(item => item.Selected).Count(); //CheckBoxList2被選擇之數量(變更次別) int max = 0; foreach (ListItem item1 in CheckBoxList1.Items) { if (item1.Selected == true) { selectedValue += item1.Value + ","; if (max < int.Parse(item1.Value)) { max = int.Parse(item1.Value); } } } DataTable vsDt = new DataTable(); vsSql = @"Select * From SubContract_Item Where SCID=" + SCID.Text + ""; vsDt = WebModel.LoadSetContentData(database, vsSql); //vsDt.Columns.Add("BKID"); vsDt.Columns.Add("ChNumber" + LbLastEdition.Text); DataRow DtRow; ViewState["DtVs"] = vsDt; if (ViewState["Dtvs_c"] != "" && ViewState["Dtvs_c"] != null) { DataTable Vsdt1 = (DataTable)ViewState["Dtvs_c"]; for (int i = 0; i < Vsdt1.Rows.Count; i++) { DataRow row = Vsdt1.Rows[i]; if (Vsdt1.Rows[i]["SC_MID"].ToString() == "0") { DtRow = vsDt.NewRow(); //DtRow["BKID"] = Vsdt1.Rows[i]["BKID"].ToString(); DtRow["SC_MID"] = Vsdt1.Rows[i]["SC_MID"].ToString(); DtRow["SCID"] = Vsdt1.Rows[i]["SCID"].ToString(); DtRow["ItemName"] = Vsdt1.Rows[i]["ItemName"].ToString(); DtRow["Unit"] = Vsdt1.Rows[i]["Unit"].ToString(); DtRow["BelongEWID"] = Vsdt1.Rows[i]["BelongEWID"].ToString() != "" ? Vsdt1.Rows[i]["BelongEWID"].ToString() : "0"; DtRow["BelongItem"] = Vsdt1.Rows[i]["BelongItem"].ToString(); DtRow["SCNumber"] = Vsdt1.Rows[i]["SCNumber"].ToString() != "" ? Vsdt1.Rows[i]["SCNumber"].ToString() : "0"; DtRow["ChNumber" + LbLastEdition.Text] = Vsdt1.Rows[i]["ChNumber" + LbLastEdition.Text].ToString(); DtRow["UnitPrice"] = Vsdt1.Rows[i]["UnitPrice"].ToString(); DtRow["ComplexPrice"] = Vsdt1.Rows[i]["ComplexPrice"].ToString() != "" ? decimal.Parse(Vsdt1.Rows[i]["ComplexPrice"].ToString()) : 0; DtRow["LastComplexPrice"] = Vsdt1.Rows[i]["LastComplexPrice"].ToString() != "" ? decimal.Parse(Vsdt1.Rows[i]["LastComplexPrice"].ToString()) : 0; DtRow["LastEdition"] = Vsdt1.Rows[i]["LastEdition"].ToString() != "" ? decimal.Parse(Vsdt1.Rows[i]["LastEdition"].ToString()) : 0; DtRow["Note"] = Vsdt1.Rows[i]["Note"].ToString(); vsDt.Rows.Add(DtRow); } else { vsDt.Rows[i]["ChNumber" + LbLastEdition.Text] = row["ChNumber" + LbLastEdition.Text].ToString(); //DataTableBox.Rows[j]["Note" + DataName + ""] = Note; } } //vsDt =(DataTable) ViewState["Dtvs_c"]; ViewState["DtVs"] = vsDt; //Vsdt1.Clear(); } //SubContract_Change追加預算的版次 DataTable Addvalue = SubContract.LoadContentData_CB(database, SCID.Text, selectedValue); //DataRow DataTableDr = Addvalue.Rows.; DataRow DataTableDr; if (Addvalue.Rows.Count > 0) { if (Addvalue.Rows.Count < vsDt.Rows.Count) { int num = vsDt.Rows.Count - Addvalue.Rows.Count; for (int j = Addvalue.Rows.Count; j < vsDt.Rows.Count; j++) { //DataTableDr = Addvalue.Rows[j]; DataTableDr = Addvalue.NewRow(); Addvalue.Columns["SCID"].AllowDBNull = true; Addvalue.Columns["LastEdition"].AllowDBNull = true; DataTableDr["SCID"] = SCID.Text; DataTableDr["UnitPrice"] = vsDt.Rows[j]["UnitPrice"].ToString(); if (max == int.Parse(LbLastEdition.Text)) { DataTableDr["ChNumber" + LbLastEdition.Text] = vsDt.Rows[j]["ChNumber" + LbLastEdition.Text].ToString(); } //Addvalue.Columns.Add("ChNumber" + LbLastEdition.Text);vsDr["SCNumber" + LbLastEdition.Text]; Addvalue.Rows.Add(DataTableDr); } } } if (vsDt.Rows.Count > 0) { for (int i = 0; i < vsDt.Rows.Count; i++) { DataRow vsDr = vsDt.Rows[i]; //string BKID = vsDr["BKID"].ToString(); string SC_MID = vsDr["SC_MID"].ToString(); string ItemName = vsDr["ItemName"].ToString(); string Unit = vsDr["Unit"].ToString(); string BelongItem = vsDr["BelongItem"].ToString(); string BelongEWID = vsDr["BelongEWID"].ToString(); string UnitPrice = vsDr["UnitPrice"].ToString(); string SCNumber = vsDr["SCNumber"].ToString() != "" ? vsDr["SCNumber"].ToString() : "0"; string ComplexPrice = ""; if (vsDr["ComplexPrice"].ToString() != "") { ComplexPrice = decimal.Parse(vsDr["ComplexPrice"].ToString()).ToString("N0"); } else if (vsDr["ComplexPrice"].ToString() == "") { ComplexPrice = (decimal.Parse(UnitPrice) * decimal.Parse(SCNumber)).ToString("N0"); } string Note = vsDr["Note"].ToString(); string Link = "SubChangeDetail.aspx?EWID=" + BelongEWID + "&SC_MID=" + SC_MID + "&edition=" + LbLastEdition.Text; tmpStr1.AppendLine(string.Format(ListStr1, ItemName, Unit, BelongItem, UnitPrice, Link)); foreach (ListItem item in CheckBoxList1.Items) { if (item.Selected == true) { if (item.Value == "0") { if (CheckBoxList2.Items[0].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", SCNumber)); } if (CheckBoxList2.Items[1].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", ComplexPrice)); } if (CheckBoxList2.Items[2].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", Note)); } } else if (Addvalue.Rows.Count > 0) { DataTableDr = Addvalue.Rows[i]; string SCNumber1 = "ChNumber" + LbLastEdition.Text + ""; if (vsDt.Columns[SCNumber1] != null && Addvalue.Columns["ChNumber" + LbLastEdition.Text] != null) { vsDt.Columns["LastEdition"].AllowDBNull = true; //Addvalue.Rows[i]["ChNumber" + LbLastEdition.Text] = vsDt.Rows[i]["ChNumber" + LbLastEdition.Text].ToString(); //Addvalue.Rows[i]["LastEdition"] = vsDt.Rows[i]["LastEdition"].ToString(); if (vsDt.Rows[i]["ChNumber" + LbLastEdition.Text].ToString() != "") { Addvalue.Rows[i]["ChNumber" + LbLastEdition.Text] = vsDt.Rows[i]["ChNumber" + LbLastEdition.Text].ToString(); Addvalue.Rows[i]["LastEdition"] = vsDt.Rows[i]["LastEdition"].ToString(); } if (Addvalue.Rows[i]["ChNumber" + LbLastEdition.Text] != "") { vsDt.Rows[i]["ChNumber" + LbLastEdition.Text] = Addvalue.Rows[i]["ChNumber" + LbLastEdition.Text].ToString(); vsDt.Rows[i]["LastEdition"] = Addvalue.Rows[i]["LastEdition"]; } } //vsDr = Addvalue.Rows[i]; string LbUnitPrice = DataTableDr["UnitPrice"].ToString() != "" ? DataTableDr["UnitPrice"].ToString() : "0"; string LbChNumber = DataTableDr["ChNumber" + item.Value + ""].ToString() != "" ? DataTableDr["ChNumber" + item.Value + ""].ToString() : "0"; string LbNote = DataTableDr["Note" + item.Value + ""].ToString(); string LbEComplex = (decimal.Parse(LbChNumber) * decimal.Parse(LbUnitPrice)).ToString("N0"); if (CheckBoxList2.Items[0].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", LbChNumber)); } if (CheckBoxList2.Items[1].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", LbEComplex)); } if (CheckBoxList2.Items[2].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", LbNote)); } } } } } tmpStr1.AppendLine(string.Format("</tr>")); } ViewState["DtVs"] = vsDt; Literal2.Text = tmpStr1.ToString(); //stopwatch.Stop(); //Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed); //} }
protected void DataContent() { string database = Session["DatabaseName"].ToString(); string vsSql = ""; //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); string ListStr1 = @"<tr><td class=""auto-style105""> <asp:Label ID=""Label738"" runat=""server"" Font-Names=""微軟正黑體"" Font-Size=""Medium"" >{2}</asp:Label> </td><td class=""auto-style105""> <asp:Label ID=""Label736"" runat=""server"" Font-Size=""Medium"" Height=""25px"">{0}</asp:Label> </td><td class=""auto-style103""> <asp:Label ID=""Label737"" runat=""server"" Font-Size=""Medium"" Height=""25px"" Width=""50px"">{1}</asp:Label> </td> <td class=""auto-style106"">{3}</td>"; string selectedValue = ""; StringBuilder tmpStr1 = new StringBuilder(); var totalcount1 = CheckBoxList1.Items.Cast <ListItem>().Where(item => item.Selected).Count(); //CheckBoxList1被選擇之數量(欄位選擇) var totalcount2 = CheckBoxList2.Items.Cast <ListItem>().Where(item => item.Selected).Count(); //CheckBoxList2被選擇之數量(變更次別) foreach (ListItem item1 in CheckBoxList1.Items) { if (item1.Selected == true) { selectedValue += item1.Value + ","; } } DataTable vsDt = new DataTable(); vsSql = @"Select * From SubContract_Item Where SCID=" + LbSCID.Text + ""; vsDt = WebModel.LoadSetContentData(database, vsSql); if (vsDt.Rows.Count > 0) { for (int i = 0; i < vsDt.Rows.Count; i++) { DataRow vsDr = vsDt.Rows[i]; string SC_MID = vsDr["SC_MID"].ToString(); string ItemName = vsDr["ItemName"].ToString(); string Unit = vsDr["Unit"].ToString(); string BelongItem = vsDr["BelongItem"].ToString(); string UnitPrice = vsDr["UnitPrice"].ToString(); string SCNumber = vsDr["SCNumber"].ToString() != "" ? vsDr["SCNumber"].ToString() : "0"; string ComplexPrice = vsDr["ComplexPrice"].ToString() != "" ? decimal.Parse(vsDr["ComplexPrice"].ToString()).ToString("N0") : "0"; string Note = vsDr["Note"].ToString(); tmpStr1.AppendLine(string.Format(ListStr1, ItemName, Unit, BelongItem, UnitPrice)); foreach (ListItem item in CheckBoxList1.Items) { if (item.Selected == true) { if (item.Value == "0") { if (CheckBoxList2.Items[0].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", SCNumber)); } if (CheckBoxList2.Items[1].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", ComplexPrice)); } if (CheckBoxList2.Items[2].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", Note)); } } else { DataTable Addvalue = SubContract.LoadContentData_CB(database, LbSCID.Text, selectedValue); if (Addvalue.Rows.Count > 0) { DataRow vsDr1 = Addvalue.Rows[i]; string LbUnitPrice = vsDr1["UnitPrice"].ToString() != "" ? vsDr1["UnitPrice"].ToString() : "0"; string LbChNumber = vsDr1["ChNumber" + item.Value + ""].ToString() != "" ? vsDr1["ChNumber" + item.Value + ""].ToString() : "0"; string LbNote = vsDr1["Note" + item.Value + ""].ToString(); string LbEComplex = (decimal.Parse(LbChNumber) * decimal.Parse(LbUnitPrice)).ToString("N0"); if (CheckBoxList2.Items[0].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", LbChNumber)); } if (CheckBoxList2.Items[1].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", LbEComplex)); } if (CheckBoxList2.Items[2].Selected == true) { tmpStr1.AppendLine(string.Format("<td class=\"auto-style106\">{0}</td>", LbNote)); } } } } } tmpStr1.AppendLine(string.Format("</tr>")); } Literal2.Text = tmpStr1.ToString(); //stopwatch.Stop(); //Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed); } }