protected void DataContent() { string database = Session["DatabaseName"].ToString(); string vsSql = ""; string LbWid = ""; string LbPriceID = ""; string LbItemOrder = ""; string LbItemName = ""; string LbUnit = ""; string LbCNumber = ""; string LbCPrice = ""; string LbCComplex = ""; string LbNotes = ""; string NowLayer = ""; string Orderlayer = ""; string order = ""; decimal LCTotal = 0; decimal LCCAL = 0; string ChAmount = ""; CToatal = 0; string ListStr3 = ""; string layer = ""; string UpperUID = ""; string order_Num = ""; string UID1 = ""; string SortNum = ""; string Find_order_Num = ""; int LayerNum = WebModel.MaxLayerSNum(database, "CBudget_WBS", Session["ProjectCode"].ToString()); if (CheckBoxList2.SelectedValue == "") { StringBuilder tmpStr3 = new StringBuilder(); DataTable vsDt = new DataTable(); vsSql = @"Select * From CBudget_WBS a left join Pro_Resource c on a.PriceID=c.PriceID Where a.PID=" + Session["ProjectCode"].ToString() + " order by order_Num"; vsDt = WebModel.LoadSetContentData(database, vsSql); if (vsDt.Rows.Count > 0) { for (int i = 0; i < vsDt.Rows.Count; i++) { Orderlayer = ""; int sort = i + 1; DataRow vsDr = vsDt.Rows[i]; LbWid = vsDr["CWid"].ToString(); LbPriceID = vsDr["PriceID"].ToString(); LbItemOrder = vsDr["ItemOrder"].ToString(); LbItemName = vsDr["ItemName"].ToString(); LbUnit = vsDr["Unit"].ToString(); LbCNumber = vsDr["CNumber"].ToString() != "" ? vsDr["CNumber"].ToString() : "0"; LbCPrice = vsDr["CPrice"].ToString() != "" ? vsDr["CPrice"].ToString() : "0"; LbCComplex = (decimal.Parse(LbCNumber) * decimal.Parse(LbCPrice)).ToString("N0"); LbNotes = vsDr["Notes"].ToString(); NowLayer = vsDr["LayerNum"].ToString() != ""?vsDr["LayerNum"].ToString():"0"; string LastCNumber = vsDr["LastCNumber"].ToString() != "" ? vsDr["LastCNumber"].ToString() : "0"; LCCAL = (decimal.Parse(LastCNumber) * decimal.Parse(LbCPrice)); string Img = LbPriceID != "" ? "visible" : "hidden"; string Img1 = LbPriceID != "" ? "" : "none"; string Link = LbPriceID != "" ? "AnalysisV_BWBS.aspx?PriceId=" + LbPriceID + " " : "#"; string Link1 = LbPriceID != "" ? "target=_blank" : ""; ChAmount = (LCCAL - decimal.Parse(LbCComplex)).ToString("N0"); if (decimal.Parse(ChAmount) > 0) { ChAmount = "+" + ChAmount + ""; } int x = 0; if (LayerNum != null) { x = LayerNum - int.Parse(NowLayer) + 1;//- int.Parse(layer) } //int x = int.Parse(LbLayerNum) - int.Parse(layer) + 1;//- int.Parse(layer) for (int j = 1; j <= int.Parse(NowLayer) - 1; j++) { Orderlayer += "<td class='itemframe' style='min-width:10px;border-left-style:none'></td>"; } order = "<td colspan= " + x + ">" + LbItemOrder + "</td>"; string color = ""; if (decimal.Parse(ChAmount) > 0) { color = "auto-style85"; } else if (decimal.Parse(ChAmount) == 0) { color = "auto-style83"; } else if (decimal.Parse(ChAmount) < 0) { color = "auto-style87"; } //show ladder information need layer = vsDr["LayerNum"].ToString(); UpperUID = vsDr["UpperWID"].ToString(); order_Num = vsDr["order_Num"].ToString(); UID1 = vsDr["CWID"].ToString(); SortNum = vsDr["SortNum"].ToString(); Find_order_Num = CBLayerCodeSort.Get_Order(database, Session["ProjectCode"].ToString(), UID1, UpperUID, order_Num, SortNum); if (layer == "1") { ListStr2 = @"<tr style=""background-color:white"" class=""treegrid-{14}"" id=tr""{14}""> <Label ID=""LbWid"" Visible=""false"" Text=""{0}""></Label> <Label ID=""LbPriceID"" Visible=""false"" Text=""{1}""></Label> {2}{3} <td class=""autoLeft"">{4}</td> <td class=""auto-style83"">{5}</td> <td class=""auto-style81"" style=""width:3%""> <a href=""{12}"" {13} ><img src="" ../img/Ana.jpg"" ToolTip=""檢視單價分析"" style=""visibility:{11};padding-left:5px;"" ></a></td> <td class=""auto-style83"" style=""text-align:right"">{6}</td> <td class=""auto-style83"" style=""text-align:right"">{7}</td> <td class=""auto-style83"" style=""text-align:right"">{8}</td> <td style=""text-align:right"" class=" + color + " >{9}</td>" + "<td style=\"text-align:left\" class=\"auto-style83\" >{10}</td>"; } else { ListStr2 = @"<tr class=""treegrid-{14} treegrid-parent-{15}"" id=tr""{14}""> <Label ID=""LbWid"" Visible=""false"" Text=""{0}""></Label> <Label ID=""LbPriceID"" Visible=""false"" Text=""{1}""></Label> {2}{3} <td class=""autoLeft"">{4}</td> <td class=""auto-style83"">{5}</td> <td class=""auto-style81"" style=""width:3%""> <a href=""{12}"" {13} ><img src="" ../img/Ana.jpg"" ToolTip=""檢視單價分析"" style=""visibility:{11};padding-left:5px;"" ></a></td> <td class=""auto-style83"" style=""text-align:right"">{6}</td> <td class=""auto-style83"" style=""text-align:right"">{7}</td> <td class=""auto-style83"" style=""text-align:right"">{8}</td> <td style=""text-align:right"" class=" + color + " >{9}</td>" + "<td style=\"text-align:left\" class=\"auto-style83\" >{10}</td>"; } tmpStr3.AppendLine(string.Format(ListStr2, LbWid, LbPriceID, Orderlayer, order, LbItemName, LbUnit, LbCNumber, LbCPrice, LbCComplex, ChAmount, LbNotes, Img, Link, Link1, sort, Find_order_Num)); CToatal += Convert.ToDecimal(LbCComplex); LCTotal += LCCAL; } LbCTotal.Text = CToatal.ToString("N0"); LbETotal.Text = LCTotal.ToString("N0"); LbSTotal.Text = (LCTotal - CToatal).ToString("N0"); } Literal3.Text = tmpStr3.ToString(); // // string count=""; // //int num = tmpStr3.ToString().LastIndexOf(count); // //var lines = tmpStr3.ToString().Split(new string[] {System.Environment.NewLine },StringSplitOptions.None).Length; //int k = 0; //int L = 0; //var myList = new List<int>(); //var myList1 = new List<int>(); //while ((k = ListStr3.IndexOf('{', k)) != -1) //{ // myList.Add(k); // k++; //} //while ((L = ListStr3.IndexOf('}', L)) != -1) //{ // myList1.Add(L); // // Increment the index. // L++; //} //var Result = new List<int>(); //int m = 0; //int at = 0; //while ((m = ListStr3.IndexOf('{', m)) != -1) //{ // at = (int.Parse(ListStr3.Substring(m + 1, ListStr2.IndexOf('}') - (ListStr2.IndexOf('{')) - 1))); // //at = int.Parse(ListStr2.Substring(ListStr2.IndexOf('{') + 1, ListStr2.IndexOf('}') - (ListStr2.IndexOf('{') + 1))); // Result.Add(at); // m++; //} } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); if (CheckBoxList2.SelectedValue != "") { ListStr3 = @"<tr class=""ShtRowSingle""> <Label ID=""LbWid"" Visible=""false"" Text=""{0}""></Label> <Label ID=""LbPriceID"" Visible=""false"" Text=""{1}""></Label> {2}{3} <td class=""autoLeft"" style=""width:300px"">{4}</td> <td class=""auto-style83"">{5}</td> <td class=""auto-style81"" style=""width:3%""> <a href=""{10}"" {11} ><img src=""../img/Ana.jpg"" ToolTip=""檢視單價分析"" style=""visibility:{9};padding-left:5%;"" ></a></td> <td class=""auto-style83"" style=""text-align:right"">{6}</td> <td class=""auto-style83"" style=""text-align:right"">{7}</td> <td class=""auto-style83"" style=""text-align:right"">{8}</td>"; string selectedValue = ""; string SQLSelect = ""; string Sum = ""; string vsSql1 = ""; //ListStr2 = ""; //int max = Result.Max(); //int min = Result.Min(); string LbNotes1 = ""; string ChAmount1 = ""; StringBuilder tmpStr2 = new StringBuilder(); List <ListItem> selected = new List <ListItem>(); //Literal3.Text = ""; CToatal = 0; LCTotal = 0; var totalcount1 = CheckBoxList1.Items.Cast <ListItem>().Where(item => item.Selected).Count(); //CheckBoxList1被選擇之數量(欄位選擇) var totalcount2 = CheckBoxList2.Items.Cast <ListItem>().Where(item => item.Selected).Count(); //CheckBoxList2被選擇之數量(變更次別) DataTable vsDt1 = new DataTable(); vsSql1 = @"Select * From CBudget_WBS a left join Pro_Resource c on a.PriceID=c.PriceID Where a.PID=" + Session["ProjectCode"].ToString() + " order by order_Num"; vsDt1 = WebModel.LoadSetContentData(database, vsSql1); foreach (ListItem item1 in CheckBoxList2.Items) { if (item1.Selected == true) { selectedValue += item1.Value + ","; } } foreach (ListItem item1 in CheckBoxList2.Items) { if (item1.Selected == true) { //selectedValue = item1.Value + ","; Sum += selectedValue; SQLSelect += (selectedValue.Length > 1) ? "or b.CEdition= " + Sum.Substring(0, Sum.Length - 1) : ""; if (vsDt1.Rows.Count > 0) { for (int i = 0; i < vsDt1.Rows.Count; i++) { string Orderlayer1 = ""; int sort = i + 1; DataRow vsDr = vsDt1.Rows[i]; string LbWid1 = vsDr["CWid"].ToString(); string LbPriceID1 = vsDr["PriceID"].ToString(); string LbItemOrder1 = vsDr["ItemOrder"].ToString(); string LbItemName1 = vsDr["ItemName"].ToString(); string LbUnit1 = vsDr["Unit"].ToString(); string LbCNumber1 = vsDr["CNumber"].ToString() != "" ? vsDr["CNumber"].ToString() : "0"; string LbCPrice1 = vsDr["CPrice"].ToString() != "" ? vsDr["CPrice"].ToString() : "0"; string LbCComplex1 = (decimal.Parse(LbCNumber1) * decimal.Parse(LbCPrice1)).ToString("N0"); LbNotes1 = vsDr["Notes"].ToString(); string NowLayer1 = vsDr["LayerNum"].ToString(); string Img = LbPriceID1 != "" ? "visible" : "hidden"; string Img1 = LbPriceID1 != "" ? "" : "none"; string Link = LbPriceID1 != "" ? "AnalysisV_BWBS.aspx?PriceId=" + LbPriceID1 + "" : "#"; string Link1 = LbPriceID1 != "" ?"target=_blank":""; string LastCNumber1 = vsDr["LastCNumber"].ToString() != "" ? vsDr["LastCNumber"].ToString() : "0"; LCCAL = (decimal.Parse(LastCNumber1) * decimal.Parse(LbCPrice1)); CToatal += Convert.ToDecimal(LbCComplex1); LbCTotal.Text = CToatal.ToString("N0"); LCTotal += LCCAL; LbETotal.Text = LCTotal.ToString("N0"); ChAmount1 = (LCCAL - decimal.Parse(LbCComplex1)).ToString("N0"); if (decimal.Parse(ChAmount1) > 0) { ChAmount1 = "+" + ChAmount1 + ""; } int x = LayerNum - int.Parse(NowLayer1) + 1;//- int.Parse(layer)項次階層計算 for (int j = 1; j <= int.Parse(NowLayer1) - 1; j++) { Orderlayer1 += "<td class='itemframe' style='min-width:10px;border-left-style:none'></td>"; } string order1 = "<td colspan= " + x + ">" + LbItemOrder1 + "</td>"; //show ladder information need layer = vsDr["LayerNum"].ToString(); UpperUID = vsDr["UpperWID"].ToString(); order_Num = vsDr["order_Num"].ToString(); UID1 = vsDr["CWID"].ToString(); SortNum = vsDr["SortNum"].ToString(); Find_order_Num = CBLayerCodeSort.Get_Order(database, Session["ProjectCode"].ToString(), UID1, UpperUID, order_Num, SortNum); if (layer == "1") { ListStr3 = @"<tr style=""background-color:white"" class=""treegrid-{12}"" id=tr""{12}""> <Label ID=""LbWid"" Visible=""false"" Text=""{0}""></Label> <Label ID=""LbPriceID"" Visible=""false"" Text=""{1}""></Label> {2}{3} <td class=""autoLeft"" style=""width:280px"">{4}</td> <td class=""auto-style83"">{5}</td> <td class=""auto-style81"" style=""width:3%""> <a href=""{10}"" {11} ><img src=""../img/Ana.jpg"" ToolTip=""檢視單價分析"" style=""visibility:{9};padding-left:5%;"" ></a></td> <td class=""auto-style83"" style=""text-align:right"">{6}</td> <td class=""auto-style83"" style=""text-align:right"">{7}</td> <td class=""auto-style83"" style=""text-align:right"">{8}</td>"; } else { ListStr3 = @"<tr class=""treegrid-{12} treegrid-parent-{13}"" id=tr""{12}""> <Label ID=""LbWid"" Visible=""false"" Text=""{0}""></Label> <Label ID=""LbPriceID"" Visible=""false"" Text=""{1}""></Label> {2}{3} <td class=""autoLeft"" style=""width:280px"">{4}</td> <td class=""auto-style83"">{5}</td> <td class=""auto-style81"" style=""width:3%""> <a href=""{10}"" {11} ><img src=""../img/Ana.jpg"" ToolTip=""檢視單價分析"" style=""visibility:{9};padding-left:5%;"" ></a></td> <td class=""auto-style83"" style=""text-align:right"">{6}</td> <td class=""auto-style83"" style=""text-align:right"">{7}</td> <td class=""auto-style83"" style=""text-align:right"">{8}</td>"; } tmpStr2.AppendLine(string.Format(ListStr3, LbWid1, LbPriceID1, Orderlayer1, order1, LbItemName1, LbUnit1, LbCNumber1, LbCPrice1, LbCComplex1, Img, Link, Link1, sort, Find_order_Num)); DataTable Addvalue = CBudgetDisp.LoadContentData_CB(database, Session["ProjectCode"].ToString(), selectedValue); foreach (ListItem item2 in CheckBoxList2.Items) { if (item2.Selected == true) { if (Addvalue.Rows.Count > 0) { DataRow vsDr1 = Addvalue.Rows[i]; string LbChNumber1 = vsDr1["ChNumber" + item2.Value + ""].ToString() != "" ? vsDr1["ChNumber" + item2.Value + ""].ToString() : "0"; if (LbChNumber1 == "0") { for (int k = int.Parse(item2.Value); k > 0; k--) { LbChNumber1 = vsDr1["ChNumber" + k + ""].ToString() != "" ? vsDr1["ChNumber" + k + ""].ToString() : "0"; if (LbChNumber1 != "0") { break; } else { LbChNumber1 = vsDr1["CNumber"].ToString() != "" ? vsDr1["CNumber"].ToString() : "0"; } } } string LbEPrice1 = vsDr1["CPrice"].ToString() != "" ? vsDr1["CPrice"].ToString() : "0"; string LbRespond1 = vsDr1["Response" + item2.Value + ""].ToString(); string LbReason1 = vsDr1["Reason" + item2.Value + ""].ToString(); //ETotal += Convert.ToDecimal(LbEComplex1); //LbETotal.Text = ETotal.ToString("N0"); string LbEComplex1 = (decimal.Parse(LbChNumber1) * decimal.Parse(LbEPrice1)).ToString("N0"); // for(int j=0; j<int.Parse(item1.Value); j++) //{ if (CheckBoxList1.Items[0].Selected == true) { tmpStr2.AppendLine(string.Format("<td class=\"auto-style83\" style=\"width:5%;text-align:right\">{0}</td>", LbChNumber1)); } if (CheckBoxList1.Items[1].Selected == true) { tmpStr2.AppendLine(string.Format("<td class=\"auto-style83\" style=\"width:5%;text-align:right\">{0}</td>", LbEPrice1)); } if (CheckBoxList1.Items[2].Selected == true) { tmpStr2.AppendLine(string.Format("<td class=\"auto-style83\" style=\"width:5%;text-align:right\">{0}</td>", LbEComplex1)); } if (CheckBoxList1.Items[3].Selected == true) { tmpStr2.AppendLine(string.Format("<td class=\"auto-style83\" style=\"width:5%;text-align:right\">{0}</td>", LbRespond1)); } if (CheckBoxList1.Items[4].Selected == true) { tmpStr2.AppendLine(string.Format("<td class=\"auto-style83\" style=\"width:5%;text-align:right\">{0}</td>", LbReason1)); } } } }//tmpStr2.AppendLine(string.Format(ListStr2, LbWid1, LbPriceID1, Orderlayer1, order1, LbItemName1, LbUnit1, LbCNumber1, LbCPrice1, LbCComplex1, LbChNumber, LbEPrice, LbEComplex, LbRespond, LbReason, LbNotes)); string color = ""; if (decimal.Parse(ChAmount1) > 0) { color = "auto-style85"; } else if (decimal.Parse(ChAmount1) == 0) { color = "auto-style83"; } else if (decimal.Parse(ChAmount1) < 0) { color = "auto-style87"; } tmpStr2.AppendLine(string.Format("<td class=\"" + color + "\" style=\"width:5%;text-align:right\">{0}</td>", ChAmount1)); tmpStr2.AppendLine(string.Format("<td class=\"auto-style83\" style=\"width:5%;text-align:left\">{0}</td></tr>", LbNotes1)); } tmpStr2.AppendLine(string.Format("<tr><td>小計</td><td colspan=\"4\" >1234</td><td colspan=\"4\">1234<td></tr>", LbNotes1)); } } } Literal3.Text = tmpStr2.ToString(); stopwatch.Stop(); // Write result. Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed); } }
//儲存資料 protected void SaveAction1(object sender, EventArgs e) { string database = Session["DatabaseName"].ToString(); //檢查標題文字 ErrorString += (DropDownList1.SelectedIndex) == 0 ? "標案請選擇!!\\n" : ""; ErrorString += (TxProjectCode.Text) == string.Empty ? "專案(工程)編號請填入!!\\n" : ""; ErrorString += (TxProjectName.Text) == string.Empty ? "專案(工程)名稱請填入!!\\n" : ""; //ErrorString += (TxProjectNickname.Text) == string.Empty ? "專案(工程)簡稱請填入!!\\n" : ""; //確認是否全選 if (ErrorString == "") { //確認選項是否存在或過期 if (Session["bid"] == null) { ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.Handler, this.GetType(), "ShowMessage", "alert(' 請重新選擇');", true); } else { //確認資料庫是否有資料 if (datacheck(Session["bid"].ToString()) == false) { string result = WebModel.SaveAction_pro(database, _TableName, GetDataBox1(), Session["ProjectCode"].ToString()); if (result != "0") { string SQLPId = "Select MAX(PID) as pid from CBudget_WBS"; int PID = int.Parse(WebModel.SItemName(database, SQLPId, "pid")) + 1; string SQLUpdateWBS = "INSERT INTO CBudget_WBS (PID,LayerCode,LayerNum,UpperWID,SortNum,ItemOrder,ItemName,Unit,ItemKind,CNumber,order_Num) SELECT " + PID + " as PID ,LayerCode,LayerNum,UpperUID as UpperWID,SortNum,ItemOrder,ItemName,Unit,ItemKind,Number as CNumber,order_Num FROM Bid_WBS where bid=" + Session["Bid"].ToString(); //bool result1 = WebModel.SQLAction(database, SQLUpdateWBS); string SQLUpdateResource = "INSERT INTO Pro_Resource (PID,ItemName,Unit,Code,Complex,AnaNumber,CPrice,ItemKind) SELECT " + PID + " as PID ,ItemName,Unit,Code,Complex,AnaNumber,Price as CPrice,ItemKind FROM Bid_Library where bid=" + Session["Bid"].ToString(); //bool result2 = WebModel.SQLAction(database, SQLUpdateResource); bool result3 = CBudgetDisp.Transfer_PriceIDtoWBS(database, Session["Bid"].ToString()); ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.Handler, this.GetType(), "ShowMessage", "alert('存檔完成');", true); } else { ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.Handler, this.GetType(), "ShowMessage", "alert('存檔失敗');", true); } } else { bool result = WebModel.EditAction_pro(database, _TableName, Session["bid"].ToString(), GetDataBox1()); if (result) { string SQLPId = "Select MAX(PID) as pid from CBudget_WBS"; int PID = int.Parse(WebModel.SItemName(database, SQLPId, "pid")) + 1; string SQLUpdateWBS = "INSERT INTO CBudget_WBS (Temp_id,PID,LayerCode,LayerNum,UpperWID,SortNum,ItemOrder,ItemName,Unit,ItemKind,CNumber,order_Num) SELECT UID," + PID + " as PID ,LayerCode,LayerNum,UpperUID as UpperWID,SortNum,ItemOrder,ItemName,Unit,ItemKind,Number as CNumber,order_Num FROM Bid_WBS where bid=" + Session["Bid"].ToString(); bool result1 = WebModel.SQLAction(database, SQLUpdateWBS); string SQLUpdateResource = "INSERT INTO Pro_Resource (Temp_id,PID,ItemName,Unit,Code,Complex,AnaNumber,CPrice,ItemKind) SELECT PriceID," + PID + " as PID ,ItemName,Unit,Code,Complex,AnaNumber,Price as CPrice,ItemKind FROM Bid_Library where bid=" + Session["Bid"].ToString(); //bool result2 = WebModel.SQLAction(database, SQLUpdateResource); bool result3 = CBudgetDisp.Transfer_PriceIDtoWBS(database, Session["Bid"].ToString()); ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.Handler, this.GetType(), "ShowMessage", "alert('修改完成');", true); } else { ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.Handler, this.GetType(), "ShowMessage", "alert('修改失敗');", true); } } } } else { ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.Handler, this.GetType(), "ShowMessage", "alert('" + ErrorString + "');", true); } }