Beispiel #1
0
        //儲存資料
        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);
            }
        }