立博名家

fox pageBase

using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Resources;
using System.Reflection;
using System.DirectoryServices;
using System.Web.Security;
using System.Data.SqlClient;
using System.Threading;
using System.Security.Principal;
using System.Configuration;
using Microsoft.Web.UI.WebControls;
using Foxconn.DAL;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using BLL;
using System.IO;

namespace CQS
{
 /// <summary>
 /// CommanPage 篕璶磞瓃
 /// </summary>
 public class PageCommon : System.Web.UI.Page
 {

  /// <summary>
  /// ノめ戈癸禜
  /// </summary>
  protected UserInfo userInfo = null;

  /// <summary>
  /// 戈方恨瞶竟
  /// </summary>
  //  ResourceManager Loc;

  string _pagename,_pagepath;
  
  //BOM 甶秨ノㄓ羬纗┮Τ璶甶秨腹,ノㄓ耞ō腹秸ノō患糤耴いゎ
  string bomstr;
  //BOM 甶秨,﹍腹癘魁
  string MainMaterialNumber,mainvaliddate,QRNo,BomLocation,AssignDate,AlternativeBom,IntraTransfer,Multibom;
  string str_MaterialTypePN,str_ProcurementTypePN,str_QuotationRoutingPN,MainPlant;
  int QRItemNo;
  CommClass.PubFunction func= new CommClass.PubFunction();

  
  public  PageCommon()
  {  

  }

  override protected void OnInit(EventArgs e){
   this.Error += new System.EventHandler(this.PageCommon_Error);
   base.OnInit(e);
  }

  private void PageCommon_Error(object serder,System.EventArgs e){
   System.Exception ex =Server.GetLastError();
   string sErrMsg = "<div style='font-bold:true'>"+ ex.Message+"</div><br>"+ ex.StackTrace ;
   Session["sErrMsg"] = sErrMsg.Replace("\n","<br>");
   Server.ClearError();

   string AbsUri =Request.Url.AbsoluteUri;
   string RawUrl = Request.RawUrl;
   string  RootUrl="";
   RootUrl = AbsUri.Substring(0, AbsUri.Length - RawUrl.Length)+Request.ApplicationPath;
//
//   string UrlAuthority;
//   UrlAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
//   UrlAuthority += HttpContext.Current.Request.ApplicationPath;
//
   // ňゎぃ穝,珿丁把计,琵 IE 粄琌ぃ呼,眖τ龟瞷穝
   Response.Redirect(RootUrl +"/ErrorMsg.aspx?Now="+ DateTime.Now.ToString() +"&MsgContent=");
  }

  #region 舦ㄧ计
  //祅嘲秈︽ō喷靡㎝舦砞﹚  
  public void Page_login(string road)
  {    
   if (Session["uID"]==null&Request["F_SysCode"]==null)
   { 
    Response.Redirect(road+"ErrorMsg.aspx?MsgID=M0003");
   }
   if(Session["uID"]==null)
   {
    func.Login_Again();//Session メア穝Login
   }
   else
   {
    if(Session["uID"].ToString()=="")
    {
     Response.Write("<script language=javascript>window.top.location='Default.aspx';</script>");
    }
   }
   //耞琌ㄣΤ赣舦
   if (Request["F_SysCode"] == null)
   {
    Response.Redirect(road+"ErrorMsg.aspx?MsgID=M0001");
    return;
   }
   if (func.haveMenu(Session["uID"].ToString(),Request["F_SysCode"].ToString()) == false)
   {
    Response.Redirect(road+"ErrorMsg.aspx?MsgID=M0001");
    return;
   }    
  }
  //絪胯/埃舦耞
  //⊿Τ絪胯/埃舦,絪胯/埃秙留旅,狦絪胯/埃秙常留旅┮よ⊿Τㄤウン玥留旅
  
  public void dg_Permit(string uID,string F_SysCode,string Edit_ID,string Del_ID,string Show_ID,System.Web.UI.WebControls.DataGridItemEventArgs e,System.Web.UI.WebControls.DataGrid e1)
  {   
   if((Edit_ID!=null)&(Del_ID!=null))
   {
    HtmlAnchor EditBtn=new HtmlAnchor();
    EditBtn=(HtmlAnchor)(e.Item.FindControl(Edit_ID));
    EditBtn.Visible=func.GetMenuPermit(uID,F_SysCode,"Edit");
    LinkButton DelBtn=new LinkButton();
    DelBtn=(LinkButton)(e.Item.FindControl(Del_ID));
    DelBtn.Visible=func.GetMenuPermit(uID,F_SysCode,"Delete");
    if(Show_ID==null)
    {
     if(EditBtn.Visible==false&DelBtn.Visible==false)
     {
      e.Item.Cells[e.Item.Cells.Count-1].Visible=false;
//      e1.Columns[e.Item.Cells.Count-1].Visible=false;
     }
    }
   }
   else
   {
    if((Edit_ID==null)&(Del_ID!=null))
    {
     LinkButton DelBtn=new LinkButton();
     DelBtn=(LinkButton)(e.Item.FindControl(Del_ID));
     DelBtn.Visible=func.GetMenuPermit(uID,F_SysCode,"Delete");
     if(Show_ID==null)
     {
      if(DelBtn.Visible==false)
      {
       e.Item.Cells[e.Item.Cells.Count-1].Visible=false;
//       e1.Columns[e.Item.Cells.Count-1].Visible=false;
      }
     }
    }
    else
    {
     if((Edit_ID!=null)&(Del_ID==null))
     {
      HtmlAnchor EditBtn=new HtmlAnchor();
      EditBtn=(HtmlAnchor)(e.Item.FindControl(Edit_ID));
      EditBtn.Visible=func.GetMenuPermit(uID,F_SysCode,"Edit");
      if(Show_ID==null)
      {
       if(EditBtn.Visible==false)
       {
        e.Item.Cells[e.Item.Cells.Count-1].Visible=false;
//        e1.Columns[e.Item.Cells.Count-1].Visible=false;
       }
      }
     }
     else
     {
      e.Item.Cells[e.Item.Cells.Count-1].Visible=false;
//      e1.Columns[e.Item.Cells.Count-1].Visible=false;
     }

    }
   }   
  }
  public bool dgedit_Permit(string uID,string F_SysCode,string Edit_ID,string Show_ID,System.Web.UI.WebControls.DataGridItemEventArgs e,System.Web.UI.WebControls.DataGrid e1)
  {
   //LinkButton DelBtn=new LinkButton();
   //DelBtn=(LinkButton)(e.Item.FindControl(Del_ID));
   HtmlAnchor EditBtn=new HtmlAnchor();
   EditBtn=(HtmlAnchor)(e.Item.FindControl(Edit_ID));
   if (func.GetMenuPermit(uID,F_SysCode,"Edit") ==false)
    EditBtn.Visible=false;
   //   DelBtn.Visible=func.GetMenuPermit(uID,F_SysCode,"Delete");
   //   //   if(e.Item.Cells[e.Item.Cells.Count-1].Controls.Count<3)
   //   //   {
   //   //    if(EditBtn.Visible==false&DelBtn.Visible==false)
   //   //    {
   //   //     e.Item.Cells[e.Item.Cells.Count-1].Visible=false;
   //   //    }
   //   //   }
   //   if(Show_ID==null)
   //   {
   //    if(EditBtn.Visible==false&DelBtn.Visible==false)
   //    {
   //     e.Item.Cells[e.Item.Cells.Count-1].Visible=false;
   //     e1.Columns[e.Item.Cells.Count-1].Visible=false;
   //    }
   //   }
   return func.GetMenuPermit(uID,F_SysCode,"Edit");
  }
  public bool dgdel_Permit(string uID,string F_SysCode,string Edit_ID,string Del_ID,string Show_ID,System.Web.UI.WebControls.DataGridItemEventArgs e,System.Web.UI.WebControls.DataGrid e1)
  {
   LinkButton DelBtn=new LinkButton();
   DelBtn=(LinkButton)(e.Item.FindControl(Del_ID));
   HtmlAnchor EditBtn=new HtmlAnchor();
   EditBtn=(HtmlAnchor)(e.Item.FindControl(Edit_ID));
   if (func.GetMenuPermit(uID,F_SysCode,"Edit") ==false)
    EditBtn.Visible=false;
   DelBtn.Visible=func.GetMenuPermit(uID,F_SysCode,"Delete");
   //   if(e.Item.Cells[e.Item.Cells.Count-1].Controls.Count<3)
   //   {
   //    if(EditBtn.Visible==false&DelBtn.Visible==false)
   //    {
   //     e.Item.Cells[e.Item.Cells.Count-1].Visible=false;
   //    }
   //   }
   if(Show_ID==null)
   {
    if(EditBtn.Visible==false&DelBtn.Visible==false)
    {
     e.Item.Cells[e.Item.Cells.Count-1].Visible=false;
//     e1.Columns[e.Item.Cells.Count-1].Visible=false;
    }
   }
   return func.GetMenuPermit(uID,F_SysCode,"Delete");

  }

  public void Plant_Permit(string uID,System.Web.UI.WebControls.DataGridItemEventArgs e,int i,string Edit_ID,string Del_ID)
  {
   
   LinkButton DelBtn=new LinkButton();
   DelBtn=(LinkButton)(e.Item.FindControl(Del_ID));
   HtmlAnchor EditBtn=new HtmlAnchor();
   EditBtn=(HtmlAnchor)(e.Item.FindControl(Edit_ID));
   EditBtn.Visible=func.GetPlantPermit(uID,e.Item.Cells[i].Text.ToString(),"Edit");
   DelBtn.Visible=func.GetPlantPermit(uID,e.Item.Cells[i].Text.ToString(),"Delete");
  }
  public void Plantedit_Permit(string uID,System.Web.UI.WebControls.DataGridItemEventArgs e,int i,string Edit_ID)
  {
   
   //LinkButton DelBtn=new LinkButton();
   //DelBtn=(LinkButton)(e.Item.FindControl(Del_ID));
   HtmlAnchor EditBtn=new HtmlAnchor();
   EditBtn=(HtmlAnchor)(e.Item.FindControl(Edit_ID));
   EditBtn.Visible=func.GetPlantPermit(uID,e.Item.Cells[i].Text.ToString(),"Edit");
   //DelBtn.Visible=func.GetPlantPermit(uID,e.Item.Cells[i].Text.ToString(),"Delete");
  }
  public void Plantdel_Permit(string uID,System.Web.UI.WebControls.DataGridItemEventArgs e,int i,string Del_ID)
  {
   
   LinkButton DelBtn=new LinkButton();
   DelBtn=(LinkButton)(e.Item.FindControl(Del_ID));
   //HtmlAnchor EditBtn=new HtmlAnchor();
   //EditBtn=(HtmlAnchor)(e.Item.FindControl(Edit_ID));
   //EditBtn.Visible=func.GetPlantPermit(uID,e.Item.Cells[i].Text.ToString(),"Edit");
   DelBtn.Visible=func.GetPlantPermit(uID,e.Item.Cells[i].Text.ToString(),"Delete");
  }

  //耞ノめ癸赣玂舦
  public void SavePermit(System.Web.UI.WebControls.Button SaveContinueBtn,System.Web.UI.WebControls.Button SaveCloseBtn,string uID,string F_SysCode,string Action)
  {
   SaveContinueBtn.Enabled=func.GetMenuPermit(uID,F_SysCode,Action);
   SaveCloseBtn.Enabled=func.GetMenuPermit(uID,F_SysCode,Action);   
  }
  #endregion

  #region Open穝怠ㄆン﹍て
  public void RegisterFunctionView()
  {
   string script;
   script="var bgColorNotSelect = '#ffffff';"+"  "+
    "var bgColorSelected = '#fceade';"+"  "+
    "var selectedLine = null;"+"  "+
    "function SelectLine(trID){"+"  "+
    "if (document.getElementById(trID) !=null){"+"  "+
    " if (selectedLine==trID){"+"  "+
    " document.getElementById(trID).style.backgroundColor = bgColorNotSelect;"+"  "+
    "} else {"+"  "+
    " if (selectedLine !=null){"+"  "+
    "  document.getElementById(selectedLine).style.background = bgColorNotSelect;"+"  "+
    " }"+"  "+
    " document.getElementById(trID).style.backgroundColor = bgColorSelected;"+"  "+
    "}"+"  "+
    "}"+"  "+
    "selectedLine=trID;"+"  "+
    "}"+"  "+
    "function OpenEditWindow(ID){"+"  "+
    "var openWnd; "+"  "+
    "openWnd=window.open('"+ PagePath +"'+ID,'"+ PageName +"','height=500,width=700,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes',null);"+"  "+
    "openWnd.moveTo((parseInt(screen.width)-700)/2,(parseInt(screen.height)-500)/2);"+"  "+
    "}";
   RegisterClientScriptBlock2("selectandedit",script);
  }
  
  //Moveㄆン﹍て
  public void RegisterFunctionEdit()
  {
   string script2;
   script2="if (typeof fcolor == 'undefined') { var fcolor = '#ffffff';}"+"  "+
    "if (typeof backcolor == 'undefined') { var backcolor = '#000000';}"+"  "+
    "if (typeof textcolor == 'undefined') { var textcolor = '#001A8C';}"+"  "+
    "if (typeof capcolor == 'undefined') { var capcolor = '#FFFFFF';}"+"  "+
    "if (typeof closecolor == 'undefined') { var closecolor = '#9999FF';}"+"  "+
    "if (typeof width == 'undefined') { var width = '400';}"+"  "+
    "if (typeof border == 'undefined') { var border = '1';}"+"  "+
    "var xPlus = 0;"+"  "+
    "var yPlus = 0;"+"  "+
    "ns4 = (document.layers)? true:false;"+"  "+
    "ie4 = (document.all)? true:false;"+"  "+
    "ie5 = (document.getElementById)? true:false;"+"  "+
    "if (ns4) over = document.overDiv;"+"  "+
    "if (ie4) over = overDiv.style;"+"  "+
    "document.onmousemove = mouseMove;"+"  "+
    "if (ns4) document.captureEvents(Event.MOUSEMOVE);"+"  "+
    "function drawMessage(text) {"+"  "+
    " dts(text);"+"  "+
    "}"+"  "+
    "function mout() {"+"  "+
    " hideObject(over);"+"  "+
    "}"+"  "+
    "function dts(text) {"+"  "+
    " txt = '<TABLE WIDTH='+width+' BORDER=0 CELLPADDING='+border+' CELLSPACING=0 BGCOLOR=LightGray><TR><TD><font face=Arial size=8pt><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR='+fcolor+'><TR><TD CLASS=P1><FONT FACE=Arial COLOR='+textcolor+'>'+text+'</FONT></TD></TR></TABLE></font></TD></TR></TABLE>';"+"  "+
    " layerWrite(txt);"+"  "+
    " disp();"+"  "+
    "}"+"  "+
    "function disp() {"+"  "+
    " xPlus = (x<400)? 1:-405;"+"  "+
    " yPlus = (y<150)? 1:150;"+"  "+
    " "+"  "+
    " moveTo(over, document.body.scrollLeft + x + xPlus, document.body.scrollTop + y);"+"  "+
    " showObject(over);"+"  "+
    "}"+"  "+
    "function mouseMove(e) {"+"  "+
    " if (ns4) {x=e.pageX; y=e.pageY;}"+"  "+
    " if (ie4) {x=event.x; y=event.y;}"+"  "+
    " if (ie5) {x=event.x; y=event.y;}"+"  "+
    " xPlus = (x<400)? 1:-405;"+"  "+
    " yPlus = (y<150)? 1:150;"+"  "+
    " moveTo(over, document.body.scrollLeft + x + xPlus, document.body.scrollTop + y);"+"  "+
    "}"+"  "+
    "function layerWrite(txt) {"+"  "+
    " if (ns4) {"+"  "+
    "  var lyr = document.overDiv.document;"+"  "+
    "  lyr.write(txt);"+"  "+
    "  lyr.close();"+"  "+
    " }"+"  "+
    " else if (ie4){"+"  "+
    "   document.all['overDiv'].innerHTML = txt;"+"  "+
    " }"+"  "+
    " else {"+"  "+
    "  document.getElementById('overDiv').innerHTML = txt;"+"  "+
    " }"+"  "+
    "}"+"  "+
    "function showObject(obj) {"+"  "+
    " if (ns4) obj.visibility = 'show';"+"  "+
    " else if (ie4) obj.visibility = 'visible';"+"  "+
    " else obj.visibility = 'visible';"+"  "+
    "}"+"  "+
    "function hideObject(obj) {"+"  "+
    " if (ns4) obj.visibility = 'hide';"+"  "+
    " else if (ie4) obj.visibility = 'hidden';"+"  "+
    " else obj.visibility = 'hidden';"+"  "+
    "}"+"  "+
    ""+"  "+
    "function moveTo(obj,xL,yL) {"+"  "+
    " obj.left = xL;"+"  "+
    " obj.top = yL;"+"  "+
    "}";

   RegisterStartupScript2("drawmessage",script2);
  }

  public void RegisterClientScriptBlock2(string key,string script)
  {
   string sScript="<script language=JavaScript>" + script + "</script>";
   base.RegisterClientScriptBlock(key,sScript);
  }
  public void RegisterStartupScript2(string key,string script)
  {
   string sScript="<script language=JavaScript>" + script + "</script>";
   base.RegisterStartupScript(key,sScript);
  }

  protected void CloseWindow()
  {
   RegisterClientScriptBlock2("SubmitCloseWindow","window.opener=null;self.close();");
  }

  protected void ShowErrMsg(string psMsg)
  {
   psMsg = psMsg.Replace("\r\n", "--");     //Right
   psMsg = psMsg.Replace("\n\r", "--");     //Right
   this.Response.Redirect("ErrMsg.aspx?errmsg=" + psMsg);
  }

  #endregion

  /// <summary>
  /// よ猭ノㄧ计程粂Τ狦┪Τreturn粂
  /// 琌RegisterClientScriptBlock诀拜肈,ぃ狝叭竟狠絏ゼ磅︽Ч紆め狠怠
  /// </summary>
  protected void AlertMsg(string psMsg)
  {
   string sMsg = psMsg.Replace("\r\n", "--");     //Right
   sMsg = psMsg.Replace("\n\r", "--");            //Right
   sMsg=sMsg.Replace("'","\'");
   this.RegisterClientScriptBlock("AlertMsg","<script language='javascript'>alert('" + sMsg + "');</script>");
  }

  public static void AlertMsg(System.Web.UI.Page pPage,string psMsg)
  {
   string sMsg = psMsg.Replace("\r\n", "--");     //Right
   sMsg = psMsg.Replace("\n\r", "--");            //Right
   sMsg=sMsg.Replace("'","\'");
   pPage.RegisterClientScriptBlock("AlertMsg","<script language='javascript'>alert('" + sMsg + "');</script>");
  }

  public string GetString(string strNo)
  {
   //粂ēや
   ResourceManager rm=new ResourceManager("CQS.SystemMsg",Assembly.GetExecutingAssembly());
   return rm.GetString(strNo);
  }

  public string GetSqlconnString()
  {
     return Symmetric.Decrypt(System.Configuration.ConfigurationSettings.AppSettings["SqlConn"],"aaaabbbb");
  }

  #region ノめ戈UserInfo
  /// <summary>
  /// 眔ノめ戈玂UseInfo摸
  /// </summary>
  /// <returns>ノめ戈癸禜</returns>
  protected UserInfo getUserInfo()
  {
   if(Session["uID"]==null)
   {
    // ⊿Τ祅嘲┪祅嘲禬┪め诀ぃ琌硄筁办祅嘲
    if(!this.User.Identity.IsAuthenticated)
    {
     //     RegisterClientScriptBlock("error","<script language=javascript>parent.document.location.href='login.aspx';</script>");
     //     if(Request.ApplicationPath + "/Default.aspx" != Request.CurrentExecutionFilePath && Request.ApplicationPath != Request.CurrentExecutionFilePath)
     //     {
     //      Response.Redirect(Request.ApplicationPath + "/Default.aspx");
     //     }
    }
    else
    {
     string[] arrUserName = this.User.Identity.Name.Trim().Split('\\');
     string userID = arrUserName.GetValue(0).ToString();
     if(arrUserName.Length>1)
     {
      userID = arrUserName.GetValue(1).ToString();
     }
     else
     {
      userID = arrUserName.GetValue(0).ToString();
     }

     if(IsValidateUser(userID))
     {
      userInfo = new UserInfo(userID);
      Session["uID"] = userID;
      //      Session["UserInfo"] = userInfo;
     }
     else
     {
      Server.Transfer("Error.aspx?MsgID=I002");
     }
    }
   }
   else
   {
    string userID = Session["uID"].ToString();
    userInfo = new UserInfo(userID);
    //    userInfo = (UserInfo)Session["UserInfo"];
   }

   //   string language = "en-us";
   //   try
   //   {
   //    HttpCookie cookie =  Request.Cookies["Language"];
   //    if(cookie!=null)
   //    {
   //     FormsAuthenticationTicket authTicket = null;
   //   
   //     authTicket = FormsAuthentication.Decrypt(cookie.Value);
   //   
   //     if(authTicket != null)
   //     {
   //      language = authTicket.Name.Trim();
   //     }
   //    }
   //   }
   //   catch
   //   {
   //   }
   //   Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(language);
   //   Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language);
   //   Loc = new ResourceManager("AIT.Location",Assembly.GetExecutingAssembly());

   return userInfo;
  }

  /// <summary>
  /// 办ノめ喷靡
  /// </summary>
  /// <param name="domain">办</param>
  /// <param name="userName">办ノめ嘿</param>
  /// <param name="password">办盞絏</param>
  /// <returns>true:硄筁喷靡 false:ゼ硄筁喷靡</returns>
  public bool IsAuthenticated(string domain, string userName, string password)
  {
   bool flag = false;
   string domainAnduserName = "";
   if(domain!="")
   {
    domainAnduserName = domain + @"\" + userName;
   }
   else
   {
    domainAnduserName = userName;
   }

   return flag;
  }

  /// <summary>
  /// 喷靡讽玡ノめ琌琌猭ノめ琌セ╰参ノめ
  /// </summary>
  /// <param name="userID">ノめID</param>
  /// <returns>true:猭; false:ぃ猭</returns>
  public bool IsValidateUser(string userID)
  {
   bool isValidate = false;
   try
   {
    //    isValidate = CPubEmployee.Exists(userID);
   }
   catch
   {
   
   }
   return isValidate; 
  }

  /// <summary>
  /// 喷靡ノめ琌琌セ╰参猭ノめ
  /// </summary>
  /// <param name="userID">ノめID</param>
  /// <param name="password">盞絏</param>
  /// <returns>true:猭 false:ぃ猭</returns>
  public bool IsUserCorrect(string userID, string password)
  {
   // ㄧ计
   bool isCorrect= false;
   try
   {
    //    if(CPubEmployee.Exists(userID))
    //    {
    //     CPubEmployee employee = new CPubEmployee(userID);
    //     if(employee.Password == FormsAuthentication.HashPasswordForStoringInConfigFile(password.Trim(), "md5"))
    //     {
    //      isCorrect = true;
    //     }
    //    }
   }
   catch
   {
   
   }
   return isCorrect; 
  }
  public string PagePath
  {
   get
   {
    return this._pagepath;
   }
   set
   {
    this._pagepath=value;
   }
  }

  public string PageName
  {
   get
   {
    return this._pagename;
   }
   set
   {
    this._pagename=value;
   }
  }
  #endregion

  #region ╲碔糃,穝甶BOM诀甶BOM祘Α,2006-08-24,2006-10-21э
  /// <summary>
  ///
  /// </summary>
  /// <param name="DataType"></param>
  /// <param name="validdate">﹚甶BOM丁,SetBomTop腹ValidDate</param>
  /// <param name="MainPN">Top腹</param>
  /// <param name="MainPlant">Top腹┮紅</param>
  /// <param name="AlternativeBomstr">纐粄1</param>
  /// <param name="AssignDatestr">﹚甶BOM丁,╰参讽玡丁┪ノめも笆﹚</param>
  /// <param name="Location">SetBom┪琌Expolding</param>
  /// <param name="Multibom">Yボ甶顶,Nボ甶Top顶</param>
  /// <param name="Procurement">ProcurementType,defaultY</param>
  /// <param name="IntraTransfer">ずユ紅,DefaultY</param>
  /// <param name="Qty">﹚甶秨bom计秖,Default1</param>
  /// <param name="QRNostr">QRNo,狦SetBomよ,肚</param>
  /// <param name="QRItemNostr">QRItemNo,SetBom0</param>
  public string SaveExplodBom_old(string DataType,string validdate, string MainPN,string MainPlantName,string AlternativeBomstr,string AssignDatestr,string Location,string Multibomstr,string Procurement,string IntraTransferstr,double Qty,string QRNostr,int QRItemNostr)
  {

   if (DataType == "") DataType="C";
   CommClass.PubFunction func= new CommClass.PubFunction();
   bomstr =MainPN;
   MainMaterialNumber=MainPN;
   MainPlant =MainPlantName;
   mainvaliddate = validdate;
   QRNo=QRNostr;
   QRItemNo =QRItemNostr;
   BomLocation =Location;
   Multibom=Multibomstr;
   AssignDate =AssignDatestr;
   AlternativeBom =AlternativeBomstr;
   IntraTransfer=IntraTransferstr;
   if (MainMaterialNumber =="")
   {
    Response.Write("<script language=javascript>alert('MaterialNumber is null!');</script>");
    return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
   }
   if (MainPlant =="")
   {
    Response.Write("<script language=javascript>alert(' Plant is null!');</script>");
    return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
   }
   string bomID="0";

//   if(QRNo !="")
//   {//埃QRBOM
//    if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') ='"+QRNo+"' and QRitemNo ='"+QRItemNo+"'") ==false)
//    {
//     Response.Write("<script language=javascript>alert('Delete the old BOM of QRNo ="+QRNo+" and QRItemNo= "+QRItemNo+" error');</script>");
//    }
//   }
   if (Location=="SetBom")
   {
    //埃讽玡ぱ玡戈
    if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') ='"+QRNo+"' and MainMaterialNumber ='"+MainMaterialNumber+"' and Plant='" + MainPlant +"' "+
     "and DataType='"+ DataType+"' and MainValidDate ='"+mainvaliddate+"' and AlternativeBom ='"+AlternativeBom+"' "+ //and AssignDate <='"+AssignDate+"'
     "and BomLocation ='"+Location+"' ") ==false)
    {
     Response.Write("<script language=javascript>alert('Delete the old BOM of MainMaterialNumber :"+MainMaterialNumber+" Failed!');</script>");
     return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
    }
   }   
   else //Approveよ,埃﹚丁ぇ玡┮Τ戈
   {
    if (UpdateOrDeletePN(MainMaterialNumber,MainPlant) ==false)
    {
//     if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') ='"+QRNo+"' and QRitemNo ='"+QRItemNo+"' "+ //and AssignDate <>'"+AssignDate+"'
//      " and MainMaterialNumber ='"+MainMaterialNumber+"'  and Plant='" + MainPlant +"' "+
//      "and DataType='"+ DataType+"' and MainValidDate ='"+mainvaliddate+"' and AlternativeBom ='"+AlternativeBom+"' "+
//      "and BomLocation ='"+Location+"' ") ==false)
     if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') ='"+QRNo+"' and QRitemNo ='"+QRItemNo+"' "+ //and AssignDate <>'"+AssignDate+"'
      "and BomLocation ='"+Location+"' ") ==false)
     {
      Response.Write("<script language=javascript>alert('Delete the old BOM of MainMaterialNumber :"+MainMaterialNumber+" before "+AssignDate+" error');</script>");
      return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
     }
    }
    if (func.GetDataTable("select * from setbomstructure where isnull(QRNo,'') ='"+QRNo+"' and QRitemNo ='"+QRItemNo+"' and MainMaterialNumber ='"+MainMaterialNumber+"'  and Plant='" + MainPlant +"' "+
     "and DataType='"+ DataType+"' and MainValidDate ='"+mainvaliddate+"' and AlternativeBom ='"+AlternativeBom+"' "+
     "and BomLocation ='"+Location+"' and AssignDate ='"+AssignDate+"' ").Tables[0].Rows.Count >0)
    { //埃﹚丁玡⑿⑤③癶
     return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
    }
   }
   //bom header郎い琩т戈
   DataSet ds_BomH = func.GetDataTable("select * from setbomheader where materialnumber='"+ MainMaterialNumber +"' and plant='"+ MainPlant +"' "+
    "and ValidDate='"+ mainvaliddate +"' and datatype='"+ DataType +"' and AlternativeBom ='"+AlternativeBom+"' and Active ='A' ");
   
   //眔腹讽玡紅い ProcurementType ,琌琌ずユ
   string Curr_ProcurementType =func.GetDataOne("select ProcurementType from pubMaterialParameter where MaterialNumber ='"+MainMaterialNumber+"' and Plant ='"+MainPlant+"' and Active ='A' ");

   if (Curr_ProcurementType =="N")
   {
    //    string InaterNal_validDate =AssignDate;
    //    string Internal_bomID =getProcurementType(MainMaterialNumber,MainPlant,DataType,AlternativeBom,IntraTransfer);
    //    
    //    if (Internal_bomID !="")
    //    {
    //     string[] arr =Internal_bomID.Split('_');
    //     MainPlant =arr[1].ToString();
    //     if (Internal_bomID !="")
    //     {
    //      if (Multibom =="Y")
    //       SaveBomItem(arr[0].ToString(),AssignDate,DataType,MainMaterialNumber,"T",bomstr,MainPlant);
    //     }
    //    }
    Response.Write("<script language=javascript>alert('ProcurementType of Top PN:"+MainMaterialNumber+" is N (Internal),No Need to Expand Bom !');</script>");
    return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN; 
   }
   //耞琌ΤQuotationRouting⊿Τ杠玥癶甶⑿⑤③祘Α
   if (this.getQuotationRouting(MainMaterialNumber)==false)
   {
    //Response.Write("<script language=javascript>alert('The QtuotationRouting of the MaterialNumber:"+MainMaterialNumber+" is null ,Expolding BOM Fail !');</script>");
    //return;
    if (bomstr.IndexOf(MainMaterialNumber,0) ==-1)
     str_QuotationRoutingPN=str_QuotationRoutingPN+","+MainMaterialNumber.ToString();
   }
   
   
   if (ds_BomH.Tables[0].Rows.Count<=0 && Curr_ProcurementType !="N")
   {
    str_MaterialTypePN=str_MaterialTypePN +","+MainMaterialNumber;
    return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN; 
   }
   else
   {
    if (Curr_ProcurementType !="N")
    {
     bomID=ds_BomH.Tables[0].Rows[0]["bomID"].ToString();
     //础⑩op腹戈,秸ノgetbomID_Dataㄧ计眔璶础计沮
     string insertstr ="Insert into setBomStructure(QRNo,QRItemNo,AssignDate,BomLocation,AlternativeBom,bomID,DataType,MainMaterialNumber,mainvaliddate,MaterialNumber,ParentPN,Plant,InternalPlant,Level,Item,DescriptionCH,DescriptionEN,Version,ProjectCode,"+
      "CMaterialNumber,CMVersion,MaterialType,PartType,BomQty,BomUnit,BHQty,BHUnit,BIQty,BIUnit,BHValidDate,BIValidDate,ComponentScrap,OperationScrap,YieldRate,PriceCategory,PurchaseModel,QuotationRouting,ProCurementType,MaterialOrigin,Remark,"+
      "AlternativeFlag,AlternativeGroup,AlternativeRate,SubstituteMaterial,AlternativeQty,AlternativeUnit,VendorByCM,VendorByFIH,NetWeight,GrossWeight,WeightUnit,Source,Active,CreateBy,ModifyBy) "
      +getbomID_Data(bomID,DataType,MainMaterialNumber,MainMaterialNumber,MainPlant,bomID,"T",Qty,false,Curr_ProcurementType);
     if (func.ExecuteSQL(insertstr) ==false)
     {
      Response.Write("<script language=javascript>alert('Exploding Bom,insert Top MaterialNumber error');</script>");
      return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
     }
 
     //秸竊ノ患耴ㄧ计睰腹┮Τ顶腹     
     SaveBomItem(bomID,AssignDate,DataType, MainMaterialNumber,"T",bomstr,MainPlant);
    }
   }

   return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
  }


  public string SaveExplodBom(string DataType,string validdate, string MainPN,string MainPlantName,string AlternativeBomstr,string AssignDatestr,string Location,string Multibomstr,string Procurement,string IntraTransferstr,double Qty,string QRNostr,int QRItemNostr)
  {

   if (DataType == "") DataType="C";
   CommClass.PubFunction func= new CommClass.PubFunction();
   bomstr =MainPN;
   MainMaterialNumber=MainPN;
   MainPlant =MainPlantName;
   mainvaliddate = validdate;
   QRNo=QRNostr;
   QRItemNo =QRItemNostr;
   BomLocation =Location;
   Multibom=Multibomstr;
   AssignDate =AssignDatestr;
   AlternativeBom =AlternativeBomstr;
   IntraTransfer=IntraTransferstr;
   if (MainMaterialNumber =="")
   {
    Response.Write("<script language=javascript>alert('MaterialNumber is null!');</script>");
    return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
   }
   if (MainPlant =="")
   {
    Response.Write("<script language=javascript>alert(' Plant is null!');</script>");
    return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
   }
   string bomID="0";

   //   if(QRNo !="")
   //   {//埃QRBOM
   //    if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') ='"+QRNo+"' and QRitemNo ='"+QRItemNo+"'") ==false)
   //    {
   //     Response.Write("<script language=javascript>alert('Delete the old BOM of QRNo ="+QRNo+" and QRItemNo= "+QRItemNo+" error');</script>");
   //    }
   //   }
   if (Location=="SetBom")
   {
    //埃讽玡ぱ玡戈
    if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') ='"+QRNo+"' and MainMaterialNumber ='"+MainMaterialNumber+"' and Plant='" + MainPlant +"' "+
     "and DataType='"+ DataType+"' and MainValidDate ='"+mainvaliddate+"' and AlternativeBom ='"+AlternativeBom+"' "+ //and AssignDate <='"+AssignDate+"'
     "and BomLocation ='"+Location+"' ") ==false)
    {
     Response.Write("<script language=javascript>alert('Delete the old BOM of MainMaterialNumber :"+MainMaterialNumber+" Failed!');</script>");
     return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
    }
   }   
   else //Approveよ,埃﹚丁ぇ玡┮Τ戈
   {
    if (UpdateOrDeletePN(MainMaterialNumber,MainPlant) ==false)
    {
     //     if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') ='"+QRNo+"' and QRitemNo ='"+QRItemNo+"' "+ //and AssignDate <>'"+AssignDate+"'
     //      " and MainMaterialNumber ='"+MainMaterialNumber+"'  and Plant='" + MainPlant +"' "+
     //      "and DataType='"+ DataType+"' and MainValidDate ='"+mainvaliddate+"' and AlternativeBom ='"+AlternativeBom+"' "+
     //      "and BomLocation ='"+Location+"' ") ==false)
     if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') ='"+QRNo+"' and QRitemNo ='"+QRItemNo+"' "+ //and AssignDate <>'"+AssignDate+"'
      "and BomLocation ='"+Location+"' ") ==false)
     {
      Response.Write("<script language=javascript>alert('Delete the old BOM of MainMaterialNumber :"+MainMaterialNumber+" before "+AssignDate+" error');</script>");
      return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
     }
    }
    if (func.GetDataTable("select * from setbomstructure where isnull(QRNo,'') ='"+QRNo+"' and QRitemNo ='"+QRItemNo+"' and MainMaterialNumber ='"+MainMaterialNumber+"'  and Plant='" + MainPlant +"' "+
     "and DataType='"+ DataType+"' and MainValidDate ='"+mainvaliddate+"' and AlternativeBom ='"+AlternativeBom+"' "+
     "and BomLocation ='"+Location+"' and AssignDate ='"+AssignDate+"' ").Tables[0].Rows.Count >0)
    { //埃﹚丁玡⑿⑤③癶
     return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
    }
   }
   //bom header郎い琩т戈
   DataSet ds_BomH = func.GetDataTable("select * from setbomheader where materialnumber='"+ MainMaterialNumber +"' and plant='"+ MainPlant +"' "+
    "and ValidDate='"+ mainvaliddate +"' and datatype='"+ DataType +"' and AlternativeBom ='"+AlternativeBom+"' and Active ='A' ");
   
   //眔腹讽玡紅い ProcurementType ,琌琌ずユ
   string Curr_ProcurementType =func.GetDataOne("select ProcurementType from pubMaterialParameter where MaterialNumber ='"+MainMaterialNumber+"' and Plant ='"+MainPlant+"' and Active ='A' ");

   if (Curr_ProcurementType =="N")//甶ずユBOM
   {
    string InaterNal_validDate =AssignDate;
    string Internal_bomID =getProcurementType(MainMaterialNumber,MainPlant,DataType,AlternativeBom,IntraTransfer);
    
    if (Internal_bomID !="")
    {
     string[] arr =Internal_bomID.Split('_');
     MainPlant =arr[1].ToString();
     if (Internal_bomID !="")
     {
      if (Multibom =="Y")
       SaveBomItem(arr[0].ToString(),AssignDate,DataType,MainMaterialNumber,"T",bomstr,MainPlant);
     }
    }
   }
   //耞琌ΤQuotationRouting⊿Τ杠玥癶甶⑿⑤③祘Α
   if (this.getQuotationRouting(MainMaterialNumber)==false)
   {
    //Response.Write("<script language=javascript>alert('The QtuotationRouting of the MaterialNumber:"+MainMaterialNumber+" is null ,Expolding BOM Fail !');</script>");
    //return;
    if (bomstr.IndexOf(MainMaterialNumber,0) ==-1)
     str_QuotationRoutingPN=str_QuotationRoutingPN+","+MainMaterialNumber.ToString();
   }
   
   
   if (ds_BomH.Tables[0].Rows.Count<=0 && Curr_ProcurementType !="N")
   {
    str_MaterialTypePN=str_MaterialTypePN +","+MainMaterialNumber;
    return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN; 
   }
   else
   {
    if (Curr_ProcurementType !="N")
    {
     bomID=ds_BomH.Tables[0].Rows[0]["bomID"].ToString();
     //础⑩op腹戈,秸ノgetbomID_Dataㄧ计眔璶础计沮
     string insertstr ="Insert into setBomStructure(QRNo,QRItemNo,AssignDate,BomLocation,AlternativeBom,bomID,DataType,MainMaterialNumber,mainvaliddate,MaterialNumber,ParentPN,Plant,InternalPlant,Level,Item,DescriptionCH,DescriptionEN,Version,ProjectCode,"+
      "CMaterialNumber,CMVersion,MaterialType,PartType,BomQty,BomUnit,BHQty,BHUnit,BIQty,BIUnit,BHValidDate,BIValidDate,ComponentScrap,OperationScrap,YieldRate,PriceCategory,PurchaseModel,QuotationRouting,ProCurementType,MaterialOrigin,Remark,"+
      "AlternativeFlag,AlternativeGroup,AlternativeRate,SubstituteMaterial,AlternativeQty,AlternativeUnit,VendorByCM,VendorByFIH,NetWeight,GrossWeight,WeightUnit,Source,Active,CreateBy,ModifyBy) "
      +getbomID_Data(bomID,DataType,MainMaterialNumber,MainMaterialNumber,MainPlant,bomID,"T",Qty,false,Curr_ProcurementType);
     if (func.ExecuteSQL(insertstr) ==false)
     {
      Response.Write("<script language=javascript>alert('Exploding Bom,insert Top MaterialNumber error');</script>");
      return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
     }
 
     //秸竊ノ患耴ㄧ计睰腹┮Τ顶腹     
     SaveBomItem(bomID,AssignDate,DataType, MainMaterialNumber,"T",bomstr,MainPlant);
    }
   }

   return str_MaterialTypePN+"_"+str_ProcurementTypePN+"_"+str_QuotationRoutingPN;
  }


  /// <summary>
  ///
  /// </summary>
  /// <param name="ParentBomID">惠璶甶BomID,bomID顶腹bomID</param>
  /// <param name="AssignDate">у﹚丁<</param>
  /// <param name="DataType"></param>
  /// <param name="ParentMaterialNumber"></param>
  /// <param name="str_Level"></param>
  /// <param name="bomstr"></param>
  /// <param name="Curr_Plant">讽玡紅い甶BOM</param>
  private void SaveBomItem(string ParentBomID,string AssignDate,string DataType,string ParentMaterialNumber,string str_Level,string bomstr,string Curr_Plant)
  {
   CommClass.PubFunction func= new CommClass.PubFunction();
   //getbomItem,тBomID┮Τ璶碻吏Item,ParentBomID顶腹bomID
   DataSet ds_item =func.GetDataTable(this.getbomItem(ParentBomID,AssignDate));
   string Level_str;
   string Parent_bomID;//讽玡bomIDParentPNbomID
   Parent_bomID=ParentBomID;
   string save_plant;// =Curr_Plant;
   string InternalbomID="",Internal_MainPlant="";
   bool InterNal =false;
   for(int i=0;i < ds_item.Tables[0].Rows.Count;i++)
   {
    save_plant =Curr_Plant;
   
    //碻吏–腹眖把计郎いт闽癘魁
    DataRow dr;
    dr= ds_item.Tables[0].Rows[i];
    Level_str =str_Level;
    //insert or update base material number
    if (str_Level !="T")
    {
     Level_str =Level_str+"."+(i+1).ToString();
    }
    else
     Level_str =(i+1).ToString();

    //眔顶腹BOMい龟悔ノ秖,眖setBomStructureい弄
    double ParentQty=getParentPNQty(MainMaterialNumber,ParentMaterialNumber,Curr_Plant,DataType,AlternativeBom);

    //眔腹讽玡紅い ProcurementType
    string Curr_ProcurementType =func.GetDataOne("select ProcurementType from pubMaterialParameter where MaterialNumber ='"+dr["Component"].ToString()+"' and Plant ='"+save_plant+"' and Active ='A' ");

    //皐癸璶碻吏Item,тΤ丁AssignDateい程掸
    DataSet ds=func.GetDataTable("select bomID,ValidDate from setBOMHeader where MaterialNumber='"+dr["Component"].ToString()+"' "+
     "and Plant='"+ Curr_Plant +"' and DataType='"+ DataType+"' and AlternativeBom ='"+AlternativeBom+"' and Active='A'" +
     " and validdate= (select max(ValidDate) from setBOMHeader where MaterialNumber='"+dr["Component"].ToString()+"' "+
     "and Plant='"+ Curr_Plant +"' and DataType='"+ DataType+"' and ValidDate <='"+AssignDate+"' and AlternativeBom ='"+AlternativeBom+"' and Active='A') " );
    
    string Internal_PN =func.GetDataOne("select ProcurementType from pubMaterialParameter where MaterialNumber ='"+dr["Component"].ToString()+"' and Plant ='"+Curr_Plant+"' and Active ='A' ");
    if (Internal_PN =="N")
    {
     string InaterNal_validDate =AssignDate;
     string Internal_bomID =getProcurementType(dr["Component"].ToString(),Curr_Plant,DataType,AlternativeBom,IntraTransfer);
    
     if (Internal_bomID !="")
     {
      InterNal=true;
      string[] arr =Internal_bomID.Split('_');
      InternalbomID =arr[0].ToString();
      Internal_MainPlant =arr[1].ToString();
      save_plant =Internal_MainPlant;
      //眔腹ずユ紅い ProcurementType
      Curr_ProcurementType =func.GetDataOne("select ProcurementType from pubMaterialParameter where MaterialNumber ='"+dr["Component"].ToString()+"' and Plant ='"+save_plant+"' and Active ='A' ");

     }
     else//ずユ紅⊿ΤBOM
     {
      save_plant=func.GetDataOne("select InternalPlant from pubMaterialParameter where MaterialNumber ='"+dr["Component"].ToString()+"' and Plant ='"+Curr_Plant+"' and Active ='A' ");
      Curr_ProcurementType ="N";
     }
    }
    

    //础セ腹计沮
    //string Plant_Save =getParentPlant(this.MainMaterialNumber,ParentMaterialNumber,this.MainPlant,DataType,this.AlternativeBom);
    if (ds.Tables[0].Rows.Count>0)
    {
     string insertstr ="Insert into setBomStructure(QRNo,QRItemNo,AssignDate,BomLocation,AlternativeBom,bomID,DataType,MainMaterialNumber,mainvaliddate,MaterialNumber,ParentPN,Plant,InternalPlant,Level,Item,DescriptionCH,DescriptionEN,Version,ProjectCode,"+
      "CMaterialNumber,CMVersion,MaterialType,PartType,BomQty,BomUnit,BHQty,BHUnit,BIQty,BIUnit,BHValidDate,BIValidDate,ComponentScrap,OperationScrap,YieldRate,PriceCategory,PurchaseModel,QuotationRouting,ProCurementType,MaterialOrigin,Remark,"+
      "AlternativeFlag,AlternativeGroup,AlternativeRate,SubstituteMaterial,AlternativeQty,AlternativeUnit,VendorByCM,VendorByFIH,NetWeight,GrossWeight,WeightUnit,Source,Active,CreateBy,ModifyBy)  "
      +getbomID_Data(Parent_bomID,DataType,ParentMaterialNumber,dr["Component"].ToString(),save_plant,dr["ID"].ToString(), Level_str,ParentQty,InterNal,Curr_ProcurementType);
     if (func.ExecuteSQL(insertstr) ==false)
     {
      Response.Write("<script language=javascript>alert('insert sub material number error');</script>");
     }
    }
    else
    {
     string insertstr ="Insert into setBomStructure(QRNo,QRItemNo,AssignDate,BomLocation,AlternativeBom,bomID,DataType,MainMaterialNumber,mainvaliddate,MaterialNumber,ParentPN,Plant,InternalPlant,Level,Item,DescriptionCH,DescriptionEN,Version,ProjectCode,"+
      "CMaterialNumber,CMVersion,MaterialType,PartType,BomQty,BomUnit,BHQty,BHUnit,BIQty,BIUnit,BHValidDate,BIValidDate,ComponentScrap,OperationScrap,YieldRate,PriceCategory,PurchaseModel,QuotationRouting,ProCurementType,MaterialOrigin,Remark,"+
      "AlternativeFlag,AlternativeGroup,AlternativeRate,SubstituteMaterial,AlternativeQty,AlternativeUnit,VendorByCM,VendorByFIH,NetWeight,GrossWeight,WeightUnit,Source,Active,CreateBy,ModifyBy)  "
      +getbomID_Data(Parent_bomID,DataType,ParentMaterialNumber,dr["Component"].ToString(),save_plant,dr["ID"].ToString(), Level_str,ParentQty,InterNal,Curr_ProcurementType);
     if (func.ExecuteSQL(insertstr) ==false)
     {
      Response.Write("<script language=javascript>alert('insert sub material number error');</script>");
     }
    }
    
    //    string Internal_PN =func.GetDataOne("select ProcurementType from pubMaterialParameter where MaterialNumber ='"+dr["Component"].ToString()+"' and Plant ='"+Curr_Plant+"' and Active ='A' ");
    //    if (Internal_PN =="N")
    //    {
    //     string InaterNal_validDate =AssignDate;
    //     string Internal_bomID =getProcurementType(dr["Component"].ToString(),Curr_Plant,DataType,AlternativeBom,IntraTransfer);
    //    
    //     if (Internal_bomID !="")
    //     {
    //      InterNal=true;
    //      string[] arr =Internal_bomID.Split('_');
    //      InternalbomID =arr[0].ToString();
    //      Internal_MainPlant =arr[1].ToString();
    //      save_plant =Internal_MainPlant;
    if (Internal_PN =="N")
    {
     if (InternalbomID !="")
     {
      if (Multibom =="Y")
       SaveBomItem(InternalbomID,AssignDate,DataType,dr["Component"].ToString(),Level_str,bomstr,save_plant);
     }
    }

//    if (Curr_ProcurementType =="F")
//     break;

    //狦ΤBOMぃ琌ずユ腹
    if (ds.Tables[0].Rows.Count >0)
    {
     if (Internal_PN !="N" && Curr_ProcurementType !="F")
     {
      //耞琌ΤQuotationRouting
      if (this.getQuotationRouting(dr["Component"].ToString())==false)
      {
       if (bomstr.IndexOf(dr["Component"].ToString(),0) ==-1)
        str_QuotationRoutingPN=str_QuotationRoutingPN+","+dr["Component"].ToString();
      }
      //Τ顶,患耴秸ノ
      if (bomstr.IndexOf(dr["Component"].ToString(),0) ==-1)
      {
       bomstr =bomstr+"_"+dr["Component"].ToString();
       if (Multibom =="Y")
        SaveBomItem(ds.Tables[0].Rows[0]["bomID"].ToString(),AssignDate,DataType,dr["Component"].ToString(),Level_str,bomstr,Curr_Plant);
      }
     }
    }
   }
  }

 

  /// <summary>
  ///
  /// </summary>
  /// <param name="ParentPNbomID">璶眔腹獺顶腹bomID</param>
  /// <param name="DataType"></param>
  /// <param name="validdate"></param>
  /// <param name="ParentPN"></param>
  /// <param name="MaterialNumber"></param>
  /// <param name="Plant"></param>
  /// <param name="ID">顶腹いID</param>
  /// <param name="Level_str"></param>
  /// <param name="ParentPNBomQty">顶腹BOMノ秖</param>
  /// <param name="InterNalTrue">琌ずユ夹в</param>
  /// <param name="ProCurementType">┮璶玂腹ProcurementType</param>
  /// <returns></returns>
  private string getbomID_Data(string ParentPNbomID,string DataType,string ParentPN,string MaterialNumber, string Plant, string ID, string Level_str,double ParentPNBomQty,bool InterNalTrue,string ProCurementType)
  {
   string str_level="";
   double str_BomQty=0;//Bomノ秖
   string str_BomUnit="";
   double str_BHQty=0;//Headerㄏノノ秖
   string str_BHUnit="";
   double str_BIQty=0;//Itemㄏノノ秖
   string str_BIUnit="";
   double BIQty=1,BHQty=1,BomQty=1;
   //だ贺薄猵矪瞶Qty
   //1Top
   //2ン
   //3潦ン
   //腹BOMノ秖,腹Itemいノ秖/腹顶腹ノ秖*顶腹BOMノ秖
   //   string bomID="0";
   string bomID =ParentPNbomID;
   string BHValidDate="";
   string BIValidDate="";
   string Item="1";
   DataSet ds_H=func.GetDataTable("select bomID,BaseQty,Unit,ValidDate from setBOMHeader where Plant ='"+Plant+"' "+
    "and MaterialNumber='"+MaterialNumber+"'  and DataType='"+ DataType +"' and "+
    "validDate<='"+ this.AssignDate+"' and alternativebom='"+AlternativeBom+"'  and Active='A' ");

   //string str_ProCurementType =func.GetDataOne("select ProcurementType from pubMaterialParameter where MaterialNumber ='"+MaterialNumber+"' and Plant ='"+Plant+"' and Active ='A' ");
   string str_ProCurementType=ProCurementType;

   
   if (Level_str !="T")
   {
    str_level=Level_str;//眔摸 .,..2㎝...3(翴腹计单计)
    DataSet ds_I =func.GetDataTable("select * from setbomItem where ID ="+ID+" and Active ='A' order by item ");
    if (ds_I.Tables[0].Rows.Count >0)
    {
     BIValidDate =string.Format("{0:yyyy-MM-dd}",ds_I.Tables[0].Rows[0]["ValidDateFrom"]);    
     //bomID = ds_I.Tables[0].Rows[0]["bomID"].ToString();
     DataTable dt =func.GetDataTable("select bomID from setbomHeader where MaterialNumber='"+MaterialNumber+"' and Plant='"+Plant+"' and Active ='A' and ValidDate <='"+this.AssignDate+"' ").Tables[0];
     if (dt.Rows.Count >0)
     {
      bomID =dt.Rows[0]["bomID"].ToString();
      
      //喷靡ProcurementType 琌タ谔
      ProcurementType_Right(str_ProCurementType,true,MaterialNumber);
     }
     else
      bomID ="0";
     
     Item =ds_I.Tables[0].Rows[0]["Item"].ToString();
     //     BIQty =(Convert.ToDouble(ds_I.Tables[0].Rows[0]["Qty"])*func.GetSrcToDestUnitRate(str_BIUnit,MainUnit));
     BIQty =Convert.ToDouble(ds_I.Tables[0].Rows[0]["Qty"]);
     //眔顶腹ノ秖,BHQty,BHQty =腹Itemノ秖*腹Headerノ秖
     DataSet ds_BHQty =func.GetDataTable("select bomID,BaseQty,Unit,ValidDate from setBOMHeader where bomID ='"+ParentPNbomID+"' ");
     if (ds_BHQty.Tables[0].Rows.Count >0)
     {
      //顶腹蝴臔ノ秖
      BHQty =Convert.ToDouble(ds_BHQty.Tables[0].Rows[0]["BaseQty"]);
     }
     else
     {
      Response.Write("<script language=javascript>alert('Get ParentPN:"+ParentPN+" Qty Error!');</script>");
      return "";
     }

     //狦ItemいbomIDHeaderいΤ癘魁,玥腹ン,ItemBOMノ秖ゲ斗*Headerノ秖     
     DataSet ds_I_H =func.GetDataTable("select * from setbomHeader where bomID ="+bomID+" and Active ='A' ");
     if (ds_I_H.Tables[0].Rows.Count >0)
     {//2ン
      //BIQty/BHQty*ParentPNBomQty
      str_BIUnit=ds_I.Tables[0].Rows[0]["Unit"].ToString();      
      //      str_BIQty =BIQty.ToString();
           
      BomQty =(BIQty/BHQty)*ParentPNBomQty;
      str_BomQty=BomQty;
      str_BomUnit =ds_I.Tables[0].Rows[0]["Unit"].ToString();
      if (ds_H.Tables[0].Rows.Count>0)
      {
       str_BIQty =BomQty;
       str_BHQty =ParentPNBomQty;
       str_BHUnit =ds_H.Tables[0].Rows[0]["Unit"].ToString();
      }
     }
     else
     {//3潦ン,狦礚癘魁玥弧腹Item い潦ン
      str_BIUnit=ds_I.Tables[0].Rows[0]["Unit"].ToString();
      str_BIQty =BIQty;

      BomQty =(BIQty/BHQty)*ParentPNBomQty;
      str_BomQty=BomQty;
      str_BomUnit =ds_I.Tables[0].Rows[0]["Unit"].ToString();

      str_BHQty =0;
      str_BHUnit =""; 

      //喷靡ProcurementType 琌タ谔
      ProcurementType_Right(str_ProCurementType,false,MaterialNumber);
     }
    }
   }
   else
   {//1Top
    str_level="Top";
    //狦Top腹,IDい肚bomID,璸衡ウbomノ秖
    DataSet ds_bom =func.GetDataTable("select * from setbomHeader where bomID ="+ID+" and Active ='A' ");
    if (ds_bom.Tables[0].Rows.Count >0)
    {
     str_BIQty =0;
     str_BIUnit ="";
     
     str_BHQty =ParentPNBomQty;
     str_BHUnit =ds_bom.Tables[0].Rows[0]["Unit"].ToString();

     str_BomQty =ParentPNBomQty;
     str_BomUnit=ds_bom.Tables[0].Rows[0]["Unit"].ToString();
    }
   } 
  
   //眖⑧outingいъセ祘▆瞯(㎝潦)
   double str_Rate=0;
   //string str_ProCurementType=ProCurementType;
   //眔腹讽玡紅い ProcurementType
//   string str_ProCurementType =func.GetDataOne("select ProcurementType from pubMaterialParameter where MaterialNumber ='"+MaterialNumber+"' and Plant ='"+Plant+"' and Active ='A' ");
   

   //ъ QuotationRouting (だΤ礚顶腹)
   string str_QuotationRouting="";
   DataSet ds=func.GetDataTable("select isnull(QuotationRouting,'') as QuotationRouting from pubMaterialMaster where  MaterialNumber='"+MaterialNumber+"' and Active='A' ");
   str_QuotationRouting =ds.Tables[0].Rows[0]["QuotationRouting"].ToString(); 
   //   DataSet ds_Q=func.GetDataTable("select MaterialNumber from setBomHeader where BomID =(select bomID from setBOMItem where Component='"+MaterialNumber+"')");
   DataSet ds_Q =func.GetDataTable("select * from setBOMItem where bomID in ( select BomID from setBomHeader "+
    "where MaterialNumber ='"+MaterialNumber+"'  and Plant='"+Plant+"' and DataType='"+ DataType +"' "+
    "and validdate <='"+ this.AssignDate+ "' and Active ='A' and AlternativeBom='"+AlternativeBom+"' ) and Active='A' order by item");
   if (ds_Q.Tables[0].Rows.Count <=0)
   {
    //顶腹 QuotationRouting
    DataSet ds_ParentPN=func.GetDataTable("select isnull(QuotationRouting,'') as QuotationRouting from pubMaterialMaster where  MaterialNumber='"+ParentPN+"' and Active='A' ");
    if ( ds_ParentPN.Tables[0].Rows.Count >0 )
    {
     str_QuotationRouting =ds_ParentPN.Tables[0].Rows[0]["QuotationRouting"].ToString();

     //耞琌Τ QuotationRouting
     QuotationRouting_Right(str_QuotationRouting,true,ParentPN);
//     if (str_QuotationRouting ==null || str_QuotationRouting =="")
//      str_QuotationRoutingPN=str_QuotationRoutingPN  +","+MaterialNumber;
//     else
//     {
//      
//      if (str_QuotationRoutingPN ==null || str_QuotationRoutingPN =="")
//       str_QuotationRoutingPN=MaterialNumber;
//      else
//      {
//       if (str_QuotationRoutingPN.ToString().IndexOf(MaterialNumber,0) ==-1)
//        str_QuotationRoutingPN=str_QuotationRoutingPN  +","+MaterialNumber;
//      }
//     }
    }
   }

   DataSet ds_Rate =func.GetDataTable("select ProcurementType,isnull(ScrapRate,0) as ScrapRate from pubMaterialParameter where  MaterialNumber='" + MaterialNumber+ "' and Plant='"+ Plant+"' and Active='A' ");
   if (ds_Rate.Tables[0].Rows.Count >0)
   {
    if (ds_Rate.Tables[0].Rows[0]["ProcurementType"].ToString() =="E")
    {//
     DataSet ds11 = func.GetDataTable("select isnull(LossRate,0) as LossRate from setRoutingItem where rtID =(select top 1 rtID from setRoutingHeader where MaterialNumber='" + MaterialNumber+ "' and Plant='"+ Plant+"' and Active='A'  order by ValidDate desc)");
     if (ds11.Tables[0].Rows.Count >0 )
     {
      str_Rate=1-Convert.ToDouble(ds11.Tables[0].Rows[0]["LossRate"].ToString());      
     }
    }
    else
    {
     if (ds_Rate.Tables[0].Rows[0]["ScrapRate"]==System.DBNull.Value)
      str_Rate =1;
     else
      str_Rate =1-Convert.ToDouble(ds_Rate.Tables[0].Rows[0]["ScrapRate"]);
    }
   }
   else
    str_Rate =1;

   //眖info Record いъ基单,潦よΑ,ㄓ方
   DataSet ds_3 =func.GetDataTable("select PriceCategory,PurchaseModel,MaterialOrigin from setInfoRecordHeader where MaterialNumber='" + MaterialNumber+ "' and Plant='"+ Plant+"' and Active='A' ");
   string str_Price="0";
   string str_Model="";
   string str_Origin="";
   if(ds_3.Tables[0].Rows.Count >0)
   {
    str_Price=ds_3.Tables[0].Rows[0]["PriceCategory"].ToString();
    str_Model=ds_3.Tables[0].Rows[0]["PurchaseModel"].ToString();
    str_Origin=ds_3.Tables[0].Rows[0]["MaterialOrigin"].ToString();
   }
      
   string instr;
   DataSet ds_HH=func.GetDataTable("select bomID,BaseQty,Unit,ValidDate from setBOMHeader where Plant ='"+Plant+"' "+
    "and MaterialNumber='"+MaterialNumber+"'  and DataType='"+ DataType +"' and "+
    "validDate <='"+ AssignDate +"' and alternativebom='"+AlternativeBom+"'  and Active='A' ");
   string PN_bomID;//狦琌ン,腹bomID,玥ウ顶腹bomID
   if (ds_HH.Tables[0].Rows.Count >0)
   {
    // >0 ボ腹琌ン, Τ顶腹, 玥(bomQt㎝BIQty传纗)
    if (Level_str =="T")
     PN_bomID =ParentPNbomID;
    else
     PN_bomID=ds_HH.Tables[0].Rows[0]["bomID"].ToString();
    instr="select "+ConvertToDBStr(QRNo)+","+QRItemNo+",'"+AssignDate+"','"+BomLocation+"','"+AlternativeBom+"',"+PN_bomID+", '"+DataType+"','"+MainMaterialNumber+"','"+ mainvaliddate+"','"+MaterialNumber+"','"+ParentPN+"','"+MainPlant+"','"+Plant+"','"+str_level+"','"+Item+"',b.DescriptionCH,b.DescriptionEN,b.Version,b.ProjectCode,"+
     "b.CMaterialNumber,b.CVersion,b.MaterialType,b.PartType,"+str_BIQty+",'"+str_BIUnit+"',"+str_BHQty+",'"+str_BHUnit+"',"+str_BomQty+",'"+str_BomUnit+"',"+
     "case when '"+BHValidDate+"'='' then NULL else '"+BHValidDate+"' end ,case when '"+BIValidDate+"'='' then NULL else '"+BIValidDate+"' end ,'0','0','"+str_Rate+"','"+str_Price+"','"+str_Model+"','"+str_QuotationRouting+"','"+str_ProCurementType+"','"+str_Origin+"',b.Remark,"+
     "'','','0','','0','','',"+
     "'',b.NetWeight,b.GrossWeight,b.WeightUnit,'M','A', '"+ Request.Cookies["LoginID"].Value +"','"+ Request.Cookies["LoginID"].Value+"' from "+
     "(select * from pubMaterialMaster  where MaterialNumber ='"+MaterialNumber+"' and Active ='A') b";
   }
   else
   {
    PN_bomID=ParentPNbomID;
    instr= "select "+ConvertToDBStr(QRNo)+","+QRItemNo+",'"+AssignDate+"','"+BomLocation+"','"+AlternativeBom+"',"+PN_bomID+",'"+DataType+"','"+MainMaterialNumber+"','"+ mainvaliddate+"','"+MaterialNumber+"','"+ParentPN+"','"+MainPlant+"','"+Plant+"','"+str_level+"',isnull(a.Item,1),b.DescriptionCH,b.DescriptionEN,b.Version,b.ProjectCode,"+
     "b.CMaterialNumber,b.CVersion,b.MaterialType,b.PartType,"+str_BIQty+",'"+str_BIUnit+"',"+str_BHQty+",'"+str_BHUnit+"',"+str_BomQty+",'"+str_BomUnit+"',"+
     "case when '"+BHValidDate+"'='' then NULL else '"+BHValidDate+"' end ,case when '"+BIValidDate+"'='' then NULL else '"+BIValidDate+"' end ,a.ComponentScrap,a.OperationScrap,'"+str_Rate+"','"+str_Price+"','"+str_Model+"','"+str_QuotationRouting+"','"+str_ProCurementType+"','"+str_Origin+"',b.Remark,"+
     "a.AlternativeFlag,a.AlternativeGroup,a.AlternativeRate,a.SubstituteMaterial,a.AlternativeQty,a.AlternativeUnit,a.VendorByCM,"+
     "a.VendorByFIH,b.NetWeight,b.GrossWeight,b.WeightUnit,'M','A', '"+ Request.Cookies["LoginID"].Value +"','"+ Request.Cookies["LoginID"].Value+"' from "+
     "(select * from setBomItem where ID ='"+ID+"' and Active ='A') a,"+
     "(select * from pubMaterialMaster  where MaterialNumber ='"+MaterialNumber+"' and Active ='A') b";
   }
   return instr;
  }

  private void ProcurementType_Right(string Curr_ProcurementType,bool SubPN,string MPN)
  {
   //耞ProcurementType 琌タ谔
   bool Flag;
   Flag =true;
   if (SubPN)
   {
    if (Curr_ProcurementType ==null || Curr_ProcurementType =="F")
     Flag =false;
             }
   else
   {
    if  (Curr_ProcurementType ==null ||Curr_ProcurementType =="E")
     Flag =false;
             }
   if (!Flag)
   {
    if (str_ProcurementTypePN ==null || str_ProcurementTypePN =="")
     str_ProcurementTypePN=MPN;
    else
    {
     if (str_ProcurementTypePN.ToString().IndexOf(MPN,0) ==-1)
      str_ProcurementTypePN=str_ProcurementTypePN  +","+MPN;
    }
   }
  }
  

  private void QuotationRouting_Right(string Curr_QuotationRouting,bool SubPN,string MPN)
  {
   //耞ProcurementType 琌タ谔
   bool Flag;
   Flag =true;
   if (SubPN)
   {
    if (Curr_QuotationRouting==null || Curr_QuotationRouting =="")
     Flag =false;
   }
   if (!Flag)
   {
    if (str_QuotationRoutingPN ==null || str_QuotationRoutingPN =="")
     str_QuotationRoutingPN=MPN;
    else
    {
     if (str_QuotationRoutingPN.ToString().IndexOf(MPN,0) ==-1)
      str_QuotationRoutingPN=str_QuotationRoutingPN  +","+MPN;
    }
   }
  }
  


  public string getbomItem(string bomID,string AssignDateTime)
  {
    //だㄢ场だтItem,场だ腹⊿ΤValidDate,场だValidDate 程掸
   //   string sql="select * from setbomItem where Active ='A' and bomID ="+bomID+" and  Component not in ("+
   //    "select Component from setbomItem where bomID ="+bomID+" group by Component having Count(*) >1) and ValidDate <='"+AssignDateTime+"' "+
   //    "union "+
   //    "select * from setbomItem where  ValidDate <='"+AssignDateTime+"' and Active ='A' and bomID ="+bomID+" and  Component =("+
   //    "select component from setbomItem where bomID ="+bomID+" group by Component having Count(*) >1) and ValidDate ="+
   //    "(select Max(ValidDate) from setbomitem where bomID="+bomID+" and Component =("+
   //    "select component from setbomItem where bomID ="+bomID+" group by Component having Count(*) >1) )";
   string sql="select * from setbomItem where Active ='A' and bomID ="+bomID+" and  Component not in ("+
    "select Component from setbomItem where bomID ="+bomID+" group by Component having Count(*) >1) and ValidDate <='"+AssignDateTime+"' "+
    "union "+
    "select a.* from setbomItem a left join ("+
    "select component,Max(ValidDate) MaxValidDate from setbomItem where bomID ="+bomID+" group by Component having Count(*) >1"+
    ") b on a.component=b.component and a.ValidDate =b.MaxValidDate where  ValidDate <='"+AssignDateTime+"' and Active ='A' and bomID ="+bomID+" order by item";
   return sql;

  }

  /// <summary>
  /// ⊿ΤQuotationRoutingFalse
  /// </summary>
  /// <param name="PN"></param>
  /// <returns></returns>
  private bool getQuotationRouting(string PN,string QRNo)
  {
   //腹讽玡紅い⊿Τbom,腹把计郎Τ⊿Τずユbom
   bool QuotationRouting_bool =true;
   if (QRNo !="")
   {
    string QuotationRouting = func.GetDataOne("select isnull(QuotationRouting,'') as QuotationRouting  from pubMaterialMaster where materialnumber='"+ PN +"' and Active ='A' ");
    if (QuotationRouting =="")
    {
     QuotationRouting_bool =false;
    }
   }
   return QuotationRouting_bool;
  }

  /// <summary>
  /// ⊿ΤQuotationRoutingFalse
  /// </summary>
  /// <param name="PN"></param>
  /// <returns></returns>
  private bool getQuotationRouting(string PN)
  {
   //腹讽玡紅い⊿Τbom,腹把计郎Τ⊿Τずユbom
   bool QuotationRouting_bool =true;
   
   string QuotationRouting = func.GetDataOne("select isnull(QuotationRouting,'') as QuotationRouting  from pubMaterialMaster where materialnumber='"+ PN +"' and Active ='A' ");
   if (QuotationRouting =="")
   {
    QuotationRouting_bool =false;
   }
   
   return QuotationRouting_bool;
  }
  private string getProcurementType(string PN,string Plantstr,string DataType,string AlternativeBom,string IntraTransfer)
  {
   string ProcurementType;
   string bomID="";///璶ずユbomID
   string return_str ="";
   string InternalPlant =Plantstr;
   //   DataSet ds_BomH = func.GetDataTable("select * from setbomheader where materialnumber='"+ PN +"' and plant='"+ InternalPlant +"' "+
   //    "and ValidDate <='"+ mainvaliddate +"' and datatype='"+ DataType +"' and AlternativeBom ='"+AlternativeBom+"' and Active ='A' "+
   //    "and ValidDate =(select max(ValidDate) from setbomHeader where materialnumber='"+ PN +"' and plant='"+ InternalPlant +"' "+
   //    "and ValidDate <='"+ mainvaliddate +"' and datatype='"+ DataType +"' and AlternativeBom ='"+AlternativeBom+"' and Active ='A' )");
   //
   //   if (ds_BomH.Tables[0].Rows.Count >0)
   //    return return_str;
   //   else //if (ds_BomH.Tables[0].Rows.Count<=0)
   //   {
   //腹讽玡紅い⊿Τbom,腹把计郎Τ⊿Τずユbom
   DataSet ds_Parameter = func.GetDataTable("select * from pubMaterialParameter where materialnumber='"+ PN +"' "+
    "and plant='"+ InternalPlant +"' and Active ='A' ");
   if (ds_Parameter.Tables[0].Rows.Count >0)
   {
    string MMType ="";
    MMType =func.GetDataOne("select MaterialType from pubmaterialmaster where MaterialNumber ='"+PN+"' and Active ='A' ");
    //     if (MMType =="S" || MMType =="F")
    //     {
    ProcurementType =ds_Parameter.Tables[0].Rows[0]["ProcurementType"].ToString();
    //狦⒅eader㎝把计郎いΤ戈玥膥尿磅︽
    if (ProcurementType =="N")
    {
     //琩腹ずユ紅ずΤ⊿ΤΤ戳ずBomID,狦Τ碞匡程Τê掸
     DataSet ds_BomH = func.GetDataTable("select * from setbomheader where materialnumber='"+ PN +"' "+
      "and plant='"+ ds_Parameter.Tables[0].Rows[0]["InternalPlant"].ToString() +"'"+
      "and datatype='"+ DataType +"' and AlternativeBom ='"+AlternativeBom+"' and Active ='A' "+
      " and ValidDate =(select max(ValidDate) from setbomheader where materialnumber='"+ PN +"' "+
      "and plant='"+ ds_Parameter.Tables[0].Rows[0]["InternalPlant"].ToString() +"'"+
      "and datatype='"+ DataType +"' and AlternativeBom ='"+AlternativeBom+"' and Active ='A' and ValidDate <='"+AssignDate+"' ) ");
     if (ds_BomH.Tables[0].Rows.Count >0)
     {
      //狦腹ずユ,沮肚把计IntraTransfer耞沮腹把计郎い腹㎝ずユ紅,块data type,bom header い琩тbom
      //string Flag =func.GetDataOne("select Flag from pubInterNalPlant where Plant ='"+InternalPlant+"' and InternalPlant ='"+ds_Parameter.Tables[0].Rows[0]["InternalPlant"].ToString()+"' ");
      bool Flag =InterNalPlant(InternalPlant,ds_Parameter.Tables[0].Rows[0]["InternalPlant"].ToString());
      if (IntraTransfer =="Y")
      {
       if (Flag)
       {
        bomID =ds_BomH.Tables[0].Rows[0]["bomID"].ToString();
        InternalPlant =ds_BomH.Tables[0].Rows[0]["Plant"].ToString();
        return_str= bomID+"_"+InternalPlant;
       }
      }
     }
     else
     {
      //Response.Write("<script language=javascript>alert('the MaterialNumber:"+PN+" is Internal ,it is need a bom!');</script>");
      str_MaterialTypePN=str_MaterialTypePN +","+PN;
     }
    }
    else if (ProcurementType =="E")     
    {
     //      if (MMType =="S" || MMType =="F")
     //      {
     //Response.Write("<script language=javascript>alert('ProcurementType of the MaterialNumber:"+PN+" is E  and MaterialType is "+MMType+" !');</script>");
     if (bomstr.IndexOf(PN,0) ==-1)
      str_MaterialTypePN=str_MaterialTypePN  +","+PN;
     //      }
    }
    else if (ProcurementType =="W")
    {
     if (bomstr.IndexOf(PN,0) ==-1)
      str_MaterialTypePN=str_MaterialTypePN +","+PN;
    }
    else if (ProcurementType =="T")
    {
     if (bomstr.IndexOf(PN,0) ==-1)
      str_MaterialTypePN=str_MaterialTypePN +","+PN;
    }
    else if (ProcurementType =="F")   
    {
     if (MMType =="S" || MMType =="F")
     {
      if (bomstr.IndexOf(PN,0) ==-1)
       str_ProcurementTypePN=str_ProcurementTypePN  +","+PN;
     }
    }
    else//ProcurementType
    {
     if (bomstr.IndexOf(PN,0) ==-1)
      str_ProcurementTypePN=str_ProcurementTypePN  +","+PN;
    }
    //else//狦ぃ琌ずユ腹,⊿ΤBOM,蝴臔Θ珇㎝Θ珇,倒莱矗ボ    
    //      Response.Write("<script language=javascript>alert('MaterialType of the MaterialNumber:"+PN+" is S or F ,it is need a bom!');</script>");

   }
   //   }
   return return_str;
  }


  public bool InterNalPlant(string MainPlant,string InterPlant)
  {
   bool Flag =false;
   if (func.GetDataTable("select Flag from pubInterNalPlant where Plant ='"+MainPlant+"' and InternalPlant ='"+InterPlant+"' and Active ='A' ").Tables[0].Rows.Count> 0)
    Flag =true;
   if (func.GetDataTable("select Flag from pubInterNalPlant where Plant ='"+InterPlant+"' and InternalPlant ='"+MainPlant+"' and Active ='A' ").Tables[0].Rows.Count >0)
    Flag =true; 
   return Flag;
  }
       

  private double getParentPNQty(string MainPN,string ParentPN,string CPlant,string DataType,string AlternativeBom)
  {//眔顶腹BOMいノ秖
   double Parent_Qty=1;
   DataSet ds_P = func.GetDataTable("select * from setbomstructure where MainMaterialNumber ='"+MainPN+"' and materialnumber='"+ ParentPN +"' "+
    "and plant='"+CPlant +"' and MainValidDate='"+ this.mainvaliddate+"' "+
    "and datatype='"+ DataType +"' and AlternativeBom ='"+AlternativeBom+"' and Active ='A' and isnull(QRNo,'')='"+QRNo+"' and BomLocation ='"+BomLocation+"'"); 
   if (ds_P.Tables[0].Rows.Count >0)
   {//setbomStructureいBIQtyボ腹ノ秖
    Parent_Qty =Convert.ToDouble(ds_P.Tables[0].Rows[0]["BIQty"].ToString());
   }

   return Parent_Qty;
  }

  private string getParentPlant(string MainPN,string ParentPN,string MainPlant,string DataType,string AlternativeBom)
  {//眔顶腹BOMいノ秖
   string ParentPlant=this.MainPlant;
   DataSet ds_P = func.GetDataTable("select * from setbomstructure where MainMaterialNumber ='"+MainPN+"' and materialnumber='"+ ParentPN +"' "+
    "and plant='"+MainPlant +"' and MainValidDate='"+ this.mainvaliddate+"' "+
    "and datatype='"+ DataType +"' and AlternativeBom ='"+AlternativeBom+"' and Active ='A' and isnull(QRNo,'')='"+QRNo+"' and BomLocation ='"+BomLocation+"'"); 
   if (ds_P.Tables[0].Rows.Count >0)
   {//setbomStructureいBIQtyボ腹ノ秖
    ParentPlant =ds_P.Tables[0].Rows[0]["InternalPlant"].ToString();
   }

   return ParentPlant;
  }

  //э腹эτ紇臫BOM挡篶

  public void ChangePN(string PN)
  {
   //тΤQR腹,┮ノ腹で皌,ぃノ腹
   DataSet ds =func.GetDataTable("select QRNo,QRItemNo,MainMaterialNumber,Plant,MainValidDate,DataType,AlternativeBom from setbomstructure "+
    " where MaterialNumber ='"+PN+"' and isnull(QRNO,'') <>'' group by QRNo,QRItemNo,MainMaterialNumber,Plant,MainValidDate,DataType,AlternativeBom");
   DataTable dt =ds.Tables[0];
   if (dt.Rows.Count >0)
   {
    for(int i=0;i<dt.Rows.Count;i++)
    {    
     //穝甶秨┮紇臫QR㎝QRItemNoBom
     DataRow dr=dt.Rows[i];
     SaveExplodBom(dr["DataType"].ToString(),String.Format("{0:yyyy-MM-dd}",dr["MainValidDate"]),dr["MainMaterialNumber"].ToString(),dr["Plant"].ToString(),dr["AlternativeBom"].ToString(),String.Format("{0:yyyy-MM-dd }",DateTime.Now),"Exploding","Y","Y","Y",1,dr["QRNo"].ToString(),Convert.ToInt32(dr["QRItemNo"].ToString()));
    }
   }
  }

  public void ChangeBom(string bomID,string PN,string Plant,string ValidDate,string DataType,string AlternativeBom)
  {
   //тΤQR腹,┮ノ腹で皌,ぃノ腹
   DataSet ds =func.GetDataTable("select QRNo,QRItemNo,MainMaterialNumber,Plant,MainValidDate,DataType,AlternativeBom from setbomstructure "+
       " where MaterialNumber ='"+PN+"' and Plant ='"+Plant+"'  and isnull(QRNO,'') <>'' group by QRNo,QRItemNo,MainMaterialNumber,Plant,MainValidDate,DataType,AlternativeBom");
   DataTable dt =ds.Tables[0];
   if (dt.Rows.Count >0)
   {
    for(int i=0;i<dt.Rows.Count;i++)
    {    
     //穝甶秨┮紇臫QR㎝QRItemNoBom
     DataRow dr=dt.Rows[i];
     SaveExplodBom(DataType,ValidDate,dr["MainMaterialNumber"].ToString(),dr["Plant"].ToString(),AlternativeBom,String.Format("{0:yyyy-MM-dd }",DateTime.Now),"Exploding","Y","Y","Y",1,dr["QRNo"].ToString(),Convert.ToInt32(dr["QRItemNo"].ToString()));
    }
   }
  }


  public void ChangeBomItem(string PN,string Plant)
  {
   //т┮Τ紇臫腹┮QRNo㎝QRItemNo,┮ノ腹で皌,ぃノ腹
   DataSet ds =func.GetDataTable("select QRNo,QRItemNo,MainMaterialNumber,Plant,MainValidDate,DataType,AlternativeBom from setbomstructure where MaterialNumber ='"+PN+"' and Plant ='"+Plant+"' and isnull(QRNO,'') <>'' group by QRNo,QRItemNo,MainMaterialNumber,Plant,MainValidDate,DataType,AlternativeBom");
   DataTable dt =ds.Tables[0];
   if (dt.Rows.Count >0)
   {
    for(int i=0;i<dt.Rows.Count;i++)
    {
     DataRow dr =dt.Rows[i];
     SaveExplodBom(dr["DataType"].ToString(),String.Format("{0:yyyy-MM-dd}",dr["MainValidDate"]),dr["MainMaterialNumber"].ToString(),dr["Plant"].ToString(),"1",String.Format("{0:yyyy-MM-dd }",DateTime.Now),"Exploding","Y","Y","Y",1,dr["QRNo"].ToString(),Convert.ToInt32(dr["QRItemNo"].ToString()));
    }
   }
  }

  #endregion


  #region そㄧ计
  public static bool IsDBNull(object pValue)
  {//耞计沮畐いNull
   if (pValue==null || pValue==DBNull.Value)
    return true;
   else
    return false;
  }

  public string ToDBData(string str)
  {
   //盢⊿Τ计计逆畐锣传Θnull玂

   if(str.Trim()=="")
    return "null";
   return  str.Trim();
  }

  /// <summary>
  /// 盢﹃锣传ΘNULL
  /// 璶ノ计逆
  /// </summary>
  /// <param name="str"></param>
  /// <returns></returns>
  public string ConvertToDBData(string str)
  {
   if(str.Trim()=="")
   {
    return "NULL";
   }
   else
   {
    return  str.Trim();
   }
  }

  /// <summary>
  /// 盢﹃锣传ΘNULL
  /// 盢才﹃虫ま腹ノㄢㄓ蠢
  /// 璶ノ才逆
  /// </summary>
  /// <param name="str">饼锣传才﹃</param>
  /// <returns>锣传才﹃</returns>
  public string ConvertToDBStr(string str)
  {
   if ( (str.Trim()=="") || (str.Trim()=="N/A") )
   {
    return "NULL";
   }
   else
   {
    return "'"+str.Trim().Replace("'","''")+"'";
   }
  }

  /// <summary>
  /// Add by reaky 2006/6/17
  /// 盢Approve戈穝跑ΘOpen篈
  /// </summary>
  /// <param name="dataname"></param>
  /// <param name="dataid"></param>
  public void changeApproveStatus(string dataname, string dataid)
  {
   string sql;
   sql = "update datQuotationApproveItem set status='Open', ApproveTime=NULL where dataname='"+ dataname +"' and dataid="+ dataid ;
   sql += "  update datQuotationApproveHeader set status='Open' from datQuotationApproveItem as a where a.qrID = datQuotationApproveHeader.qrID and a.dataname='"+ dataname +"' and a.dataid="+ dataid;
   if (func.ExecuteSQL(sql) == false)
   {
    func.ExecuteJS("alert('update approve status fail!');");
   }
  }

  /// <summary>
  /// Add by reaky 2006/6/17
  /// 浪代ゲ琿逆琌﹚
  /// 狦⊿Τ玥穦倒牡
  /// </summary>
  /// <param name="field"></param>
  /// <param name="values"></param>
  public bool checkMustBe(string values, string field)
  {
   if (values.Trim() == "")
   {
    func.AlertMsg(field + " must assign value");
    return false;
   }
   else
   {
    return true;
   }
  }

  /// <summary>
  /// ъ癸莱絏冈灿磞瓃
  /// ъ瓣絏癸莱瓣產单
  /// </summary>
  /// <param name="tablename">璶ъ虫,cqsParameter</param>
  /// <param name="fieldname">璶ъ逆,text</param>
  /// <param name="condition">璶ъ兵ン,category=??</param>
  /// <returns></returns>
  public string getDesc(string tablename, string fieldname, string condition)
  {
   string rs="";
   DataSet ds;
   ds = func.GetDataTable("select "+ fieldname +" from "+ tablename +" where "+ condition);
   if (ds.Tables[0].Rows.Count>0)
   {
    rs = ds.Tables[0].Rows[0][fieldname].ToString();
   }
   return rs;
  }

  public string getIdent_Current(string tablename)
  {
   DataSet ds;
   ds = func.GetDataTable("select ident_current('"+ tablename +"') as ID ");
   if (ds.Tables[0].Rows.Count>0)
   {
    return ds.Tables[0].Rows[0]["ID"].ToString();
   }
   else
   {
    return "0";
   }
  }

  /// <summary>
  /// 秸ノㄧ计莉 DataType
  /// </summary>
  /// <param name="PN"></param>
  /// <param name="Plant"></param>
  /// <param name="QRNo"></param>
  /// <param name="QrItemNo"></param>
  /// <returns></returns>
  public string getBOMdatatype(string PN, string Plant, string QRNo, string QrItemNo)
  {// C_MainValidDate
   getBomFirst(QRNo,Convert.ToInt32(QrItemNo));
   DataSet ds;
   //ds = func.GetDataTable("select dbo.fn_getBOMDataType("+ ConvertToDBStr(PN) +","+ ConvertToDBStr(Plant) +","+ ConvertToDBStr(QRNo) +","+ ConvertToDBStr(QrItemNo) +") as datatype");
   if (QRNo != "" && QrItemNo != "")
   {
    ds = func.GetDataTable("select distinct * from setBomstructure where QRNo ='"+QRNo+"' and QRItemNo ='"+QrItemNo+"' ");
    if (ds.Tables[0].Rows.Count >0)
    {
     DataRow dr =ds.Tables[0].Rows[0];
     return "C_"+string.Format("{0:yyyy-MM-dd}",dr["MainValidDate"]);
    }
    else
    {
     ds = func.GetDataTable("select Max(ValidDate) as validDate from setBomHeader where MaterialNumber ='"+PN+"' and Plant ='"+Plant+"' and DataType ='C' and Active ='A' ");
     if (ds.Tables[0].Rows.Count >0)
     {
      DataRow dr =ds.Tables[0].Rows[0];
      return "C_"+string.Format("{0:yyyy-MM-dd}",dr["validDate"]);
     }
    }
   }
   else
   {
    ds = func.GetDataTable("select Max(ValidDate) as validDate from setBomHeader where MaterialNumber ='"+PN+"' and Plant ='"+Plant+"' and DataType ='C' and Active ='A' ");
    if (ds.Tables[0].Rows.Count >0)
    {
     DataRow dr =ds.Tables[0].Rows[0];
     return "C_"+string.Format("{0:yyyy-MM-dd}",dr["validDate"]);
    }
   }
   return "C_9999/01/01";
   
  }

  public string getBOMdatatype_cost(string PN, string Plant, string QRNo, string QrItemNo)
  {
   DataSet ds;
   getBomFirst(QRNo,Convert.ToInt32(QrItemNo));
   //ds = func.GetDataTable("select dbo.fn_getBOMDataType_cost("+ ConvertToDBStr(PN) +","+ ConvertToDBStr(Plant) +","+ ConvertToDBStr(QRNo) +","+ ConvertToDBStr(QrItemNo) +") as datatype");
   //return ds.Tables[0].Rows[0]["datatype"].ToString();
   if (QRNo != "" && QrItemNo != "")
   {
    ds = func.GetDataTable("select distinct * from setBomstructure where QRNo ='"+QRNo+"' and QRItemNo ='"+QrItemNo+"' ");
    if (ds.Tables[0].Rows.Count >0)
    {
     DataRow dr =ds.Tables[0].Rows[0];
     return "C_"+string.Format("{0:yyyy-MM-dd}",dr["MainValidDate"]);
    }
    else
    {
     ds = func.GetDataTable("select Max(ValidDate) as validDate from setBomHeader where MaterialNumber ='"+PN+"' and Plant ='"+Plant+"' and DataType ='C' and Active ='A' ");
     if (ds.Tables[0].Rows.Count >0)
     {
      DataRow dr =ds.Tables[0].Rows[0];
      return "C_"+string.Format("{0:yyyy-MM-dd}",dr["validDate"]);
     }
    }
   }
   else
   {
    ds = func.GetDataTable("select Max(ValidDate) as validDate from setBomHeader where MaterialNumber ='"+PN+"' and Plant ='"+Plant+"' and DataType ='C' and Active ='A' ");
    if (ds.Tables[0].Rows.Count >0)
    {
     DataRow dr =ds.Tables[0].Rows[0];
     return "C_"+string.Format("{0:yyyy-MM-dd}",dr["validDate"]);
    }
   }
   return "C_9999/01/01";
  }

  /// <summary>
  /// 莉癸莱QR虫 bom,routing,inforecordApprove猵
  /// Τ场常Approve厨基玥ぃす砛
  /// </summary>
  /// <param name="qhID"></param>
  /// <returns></returns>
  [Ajax.AjaxMethod]
  public string getApproveStatus(string qhID)
  {
   string app="0";
   DataSet ds, da;
   ds = func.GetDataTable("select * from datQuotationHeader where qhID="+ qhID);
   if (ds.Tables[0].Rows.Count >0)
   {
    da = func.GetDataTable("select dbo.fn_getApproveStatus('"+ ds.Tables[0].Rows[0]["QrNo"].ToString()+"',"+ ds.Tables[0].Rows[0]["QrItemNo"].ToString()+") as app ");
    app = da.Tables[0].Rows[0]["app"].ToString();
   }
   return app;
  }

  /// <summary>
  /// 莉癸莱QR虫 bom,routing,inforecordApprove猵
  /// Τ场常Approve厨基玥ぃす砛
  /// </summary>
  /// <param name="qhID"></param>
  /// <returns></returns>
  [Ajax.AjaxMethod]
  public string getApproveStatusDetail_cost(string CEID)
  {
   string app="0";
   DataSet ds, da;
   ds = func.GetDataTable("select * from datcostEstimateH where CEID="+ CEID);
   if (ds.Tables[0].Rows.Count >0)
   {
    da = func.GetDataTable("select dbo.fn_getApproveStatusDetail('"+ ds.Tables[0].Rows[0]["QrNo"].ToString()+"',"+ ds.Tables[0].Rows[0]["QrItemNo"].ToString()+") as app ");
    app = da.Tables[0].Rows[0]["app"].ToString();
   }
   return app;
  }

  [Ajax.AjaxMethod]
  public string getApproveStatus_cost(string CEID)
  {
   string app="0";
   DataSet ds, da;
   ds = func.GetDataTable("select * from datcostEstimateH where CEID="+ CEID);
   if (ds.Tables[0].Rows.Count >0)
   {
    da = func.GetDataTable("select dbo.fn_getApproveStatus('"+ ds.Tables[0].Rows[0]["QrNo"].ToString()+"',"+ ds.Tables[0].Rows[0]["QrItemNo"].ToString()+") as app ");
    app = da.Tables[0].Rows[0]["app"].ToString();
   }
   return app;
  }
  public string getUserPlant(string uid)
  {
   return "select plantID from cqsUserPlant where uid="+ uid;
  }

  //浪琩琘datagrid琌陪ボ埃癘魁
  public bool setIsShowDel(string f_syscode)
  {
   DataSet ds;
   string LoginID = Session["LoginID"].ToString();
   ds = func.GetDataTable("select delflag from setDel where uID='"+LoginID+"' and delflag=1 and F_syscode='"+f_syscode+"'");
   if (ds.Tables[0].Rows.Count>0)
   {
    return true;
   }
   else
   {
    return false;
   }   
  
  }

  //浪琩琘厨基虫厨基虫腹琌確確玥腹_1,_2
  public string PNtitlestr(string  qhid)
  {
   string PN="";
   string QRNO="";
   string QRItemNO="";
   string QHNO="";
   DataTable dt=func.GetDataTable("select qhno,qritemno,qrno,MaterialNumber from datquotationHeader where qhid="+qhid).Tables[0];
   if(dt.Rows.Count>0)
   {
    QRNO=dt.Rows[0]["qrno"].ToString();
    QRItemNO=dt.Rows[0]["qritemno"].ToString();
    QHNO=dt.Rows[0]["qhno"].ToString();
    PN=dt.Rows[0]["MaterialNumber"].ToString();
   }
   if(QHNO.Length>14)
   {
    string num=func.GetDataOne("select count(*) from datquotationHeader where qhno like '%"+PN+"%' and qrno='"+QRNO+"' and QRItemNO="+QRItemNO+" and qhid<"+qhid);
    if(num!="0")
    {
     PN=PN+"_"+num;
    }
    
   }
   return PN;
  }

  /// <summary>
  /// 砞竚ㄣ逆秙瓜ノ┪ぃノ
  /// </summary>
  /// <param name="toolbar">ㄣ逆</param>
  /// <param name="Index">ま</param>
  /// <param name="Enabled">true:ノ false:ぃノ</param>
  public void setToolbarEnabled(Toolbar toolbar, int Index, bool Enabled)
  {
   ToolbarButton tbBtn = (ToolbarButton)toolbar.Items[Index];
   tbBtn.Enabled = Enabled;
   string imageUrl = tbBtn.ImageUrl.Trim();
   string url = imageUrl.Substring(0,imageUrl.LastIndexOf("/"));
   string fileName = imageUrl.Substring(imageUrl.LastIndexOf("/") + 1);
   string fileNameBegin = fileName.Substring(0,fileName.LastIndexOf("."));
   string fileNameEnd = fileName.Substring(fileName.LastIndexOf(".") + 1);
   int point = fileNameBegin.LastIndexOf("_");
   if(point>=0)
   {
    fileNameBegin = fileNameBegin.Substring(0,fileNameBegin.LastIndexOf("_"));
   }

   if(Enabled)
   {
    tbBtn.ImageUrl = url + "/" + fileNameBegin + "_t." + fileNameEnd;
   }
   else
   {
    tbBtn.ImageUrl = url + "/" + fileNameBegin + "_f." + fileNameEnd;
   }
  }
  //沮腹т璣ゅ磞瓃
  public string  PNdescriptionstr(string PN)
  {
   string PNDescriptEN=func.GetDataOne("select DescriptionEN from pubmaterialmaster where materialnumber='"+PN+"'");
   if(PNDescriptEN==null)
   {
    PNDescriptEN=PN;
   }
   return PNDescriptEN;
  }
  #endregion


  #region getBomFirst,╲碔糃,QRNO㎝QRItemNO  斑谔﹚BOM兵ン,ㄧ计ノㄓ耞狦QR⊿ΤBOM,玥甶BOM
  /// <summary>
  /// ㄧ计ノ硚:
  /// 1ㄏノBOMよApproveCheck Data status
  /// 2QR琩高よ
  /// </summary>
  /// <param name="QRNo">QRNo,string</param>
  /// <param name="QRItemNo">QRItemNo,int</param>
  public void getBomFirst(string QRNo,int QRItemNo)
  {
   //﹚甶BOM丁,QRミ丁┪Release丁
   DataSet ds_Date = func.GetDataTable("select MaterialNumber,Plant,case when releasedate is not null and releasedate>=QRHCreateOn then releasedate else QRHCreateOn end as assigndate from vdatQRItem "+
    "where qrno='" +QRNo+"' and qritemno="+QRItemNo);
   
   if (ds_Date.Tables[0].Rows.Count>0)
   {
    string AssignDate =String.Format("{0:yyyy-MM-dd}",ds_Date.Tables[0].Rows[0]["assigndate"]);
    string MainMaterialNumber =ds_Date.Tables[0].Rows[0]["MaterialNumber"].ToString();
    string MainPlant =ds_Date.Tables[0].Rows[0]["Plant"].ToString();
   
    //眖BOMHeaderい弄﹚丁程掸戈
    DataSet ds_bom =func.GetDataTable("select Max(ValidDate) as MainValidDate from setbomHeader where MaterialNumber ='"+MainMaterialNumber+"' and Plant ='"+MainPlant+"' "+
     "and DataType ='C' and AlternativeBom =1 and ValidDate <= '"+AssignDate+"' and Active ='A' ");
    DataRow dr =ds_bom.Tables[0].Rows[0];
    if (ds_bom.Tables[0].Rows.Count >0)
    {
     string DataType ="C";
    
     double BomQty =1;//﹚Top腹甶Bomノ秖,纐粄1
     string MainValidDate=String.Format("{0:yyyy-MM-dd}",dr["MainValidDate"]);
    
     string Location ="Exploding";
     string AlternativeBom="1";

     //狦QRNO⊿ΤBOM,玥穝甶BOM
     if (func.GetDataTable("select * from setbomstructure where QRNo ='"+QRNo+"'  and QRItemNo='" +QRItemNo+"' ").Tables[0].Rows.Count <=0)
      SaveExplodBom(DataType,MainValidDate,MainMaterialNumber,MainPlant,AlternativeBom,AssignDate,Location,"Y","Y","Y",BomQty,QRNo,QRItemNo);
    }
    else
    {
     func.AlertMsg("PN:" + MainMaterialNumber +" has not any Active BOM in "+MainPlant+", please set BOM first!");
     return;
    }
   }
   else
   {
    func.AlertMsg("QR:" + QRNo +" and "+QRItemNo+" found fail,Plesse check it!");
    return;
   }
  }
  #endregion


  #region UpdateOrDeletePN,╲碔糃,耞癸腹秈︽э㎝埃
  /// <summary>
  /// 沮PN㎝Plant 埃 setBomHeader,setBomItem┪pubMaterialMasterい癘魁
  /// True ,弧戈,ぃ埃
  /// </summary>
  /// <param name="PN"></param>
  /// <param name="Plant"></param>
  /// <returns></returns>
  public bool UpdateOrDeletePN(string PN,string Plant)
  {//т璶絪胯┪埃腹
   //狦QR砆Close,玥ぃ埃
   DataSet ds =func.GetDataTable("select * from vdatQRItem where MaterialNumber ='"+PN+"' and Plant ='"+Plant+"' and isnull(CloseDate,'') !='' and Active ='A' ");
   if (ds.Tables[0].Rows.Count >0)
    return true;
   else
    return false;
  }

  /// <summary>
  /// 沮ID埃 setBomHeader,setBomItem┪pubMaterialMasterい癘魁
  /// True ,弧戈,ぃ埃
  /// </summary>
  /// <param name="ID">bomID┪BomItemいID</param>
  /// <param name="TableName">setBomHeader,setBomItem┪pubMaterialMaster</param>
  public bool UpdateOrDeletePN(int ID,string TableName)
  {//т璶絪胯┪埃腹
   string sqlstr;
   DataSet ds,ds_PN;
   DataRow dr_PN;
   if (TableName.ToLower() =="setbomheader")
    sqlstr ="select * from setBomHeader where bomID ="+ID+" and Active ='A' ";
   else if (TableName.ToLower() =="setbomitem")
    sqlstr ="select * from setBomItem where ID ="+ID+" and Active ='A' ";
   else
   {
    sqlstr ="select * from pubMaterialMaster where pnID ="+ID+" and Active ='A' ";
    ds_PN =func.GetDataTable(sqlstr);
    if (ds_PN.Tables[0].Rows.Count>0)
    {
     dr_PN =ds_PN.Tables[0].Rows[0];
     //狦QR砆Close,玥ぃ埃
     ds =func.GetDataTable("select * from vdatQRItem where MaterialNumber ='"+dr_PN["MaterialNumber"].ToString()+"' and isnull(CloseDate,'') !='' and Active ='A' ");
     if (ds.Tables[0].Rows.Count >0)
      return true;
     else
      return false;
    }
    else
     return false;
   }
   ds_PN =func.GetDataTable(sqlstr);
   if (ds_PN.Tables[0].Rows.Count>0)
   {
    dr_PN =ds_PN.Tables[0].Rows[0];
    //狦QR砆Close,玥ぃ埃
    ds =func.GetDataTable("select * from vdatQRItem where MaterialNumber ='"+dr_PN["MaterialNumber"].ToString()+"' and Plant ='"+dr_PN["Plant"].ToString()+"' and isnull(CloseDate,'') <>'' and Active ='A' ");
    if (ds.Tables[0].Rows.Count >0)
     return true;
    else
     return false;
   }
   else
    return false;

  }
  #endregion


  #region DeleteBom,╲碔糃,埃Bom戈,腹戈эぇ,ぃ甶,穦getBomFirstい穝甶Bom

  public void DeleteBom(string PN,string Plant,string MainValidDate,string DataType)
  {
   //т┮Τ紇臫腹,┮ノ腹で皌,ぃノ腹
   DataSet ds =func.GetDataTable("select MainMaterialNumber,Plant,MainValidDate,DataType from setbomstructure "+
    "where MaterialNumber ='"+PN+"' and Plant ='"+Plant+"' and MainValidDate ='"+ MainValidDate+"' and "+
    "DataType ='"+DataType+"'  group by MainMaterialNumber,Plant,MainValidDate,DataType");
   DataTable dt =ds.Tables[0];
   if (dt.Rows.Count >0)
   {
    for(int i=0;i<dt.Rows.Count;i++)
    {
     //穝磅︽BOM甶秨,р BomLocation ='Exploding' 场癘魁埃
     if (func.ExecuteSQL("delete from setBomStructure where isnull(QRNo,'') <>'' and MainMaterialNumber ='"+dt.Rows[i]["MainMaterialNumber"].ToString()+"' and Plant='" + dt.Rows[i]["Plant"].ToString() +"' "+
      "and DataType='"+ dt.Rows[i]["DataType"].ToString()+"' and MainValidDate ='"+string.Format("{0:yyyy-MM-dd}",dt.Rows[i]["MainValidDate"])+"' and BomLocation ='Exploding' ") ==false)
     {
      Response.Write("<script language=javascript>alert('Delete the old BOM of "+dt.Rows[i]["MainMaterialNumber"].ToString()+" error');</script>");
      return;
     }
    }
   }
   //    else
   //     Response.Write("<script language=javascript>alert('Can find the updated BOM,Update BOM fail!');</script>");
  }

  #endregion


  #region QRReleaseFirst,╲碔糃,Approve兜ヘぇ玡,谔﹚QR琌Τ砆 Release

  public string QRReleaseFirst(string QRNo,string QRItemNo)
  {
   //DataSet ds_Date = func.GetDataTable("select releasedate as assigndate from vdatQRItem where qrno='" + QRNo +"' and releasedate <>'' and qritemno="+ QRItemNo);
   //DataSet ds_Date = func.GetDataTable("select assigndate from vdatQuotationApprove where qrno='" + QRNo +"' and assigndate <>'' and qritemno="+ QRItemNo);
   DataSet ds_Date = func.GetDataTable("select releasedate from datQRHeader where qrno='" + QRNo +"' and releasedate <>'' ");
   string releasedate="";
   if (ds_Date.Tables[0].Rows.Count>0)
   {
    releasedate =String.Format("{0:yyyy-MM-dd}",ds_Date.Tables[0].Rows[0]["releasedate"]);
   }
   else
   {
    func.AlertMsg("QRNO :" + QRNo +" has not realesed, please Realse QR first!");    
   }
   return releasedate;
  }
  #endregion


  #region  膀セ戈跑笆倒砞﹚闽ノめ祇癳email,ル
  public int sendMailApproved(string dataname,int dataid,string loginid,string data)
  {
   return sendMailApproved(dataname,dataid,loginid,data);
  }
  #endregion


  #region ╲碔糃,倒DataGrid 肅︹跋だ癘魁
  /// <summary>
  /// DataGrid琘逆ノ丁筳︹ㄓ跋だ陪ボ
  /// </summary>
  /// <param name="dg">DataGrid嘿</param>
  /// <param name="Col">ゑ耕逆俱</param>
  public void SetDataGridColor(System.Web.UI.WebControls.DataGrid dg, params int[] Col)
  {
   int cc=dg.Items.Count;
   //bool flg =true;
   //DataGridい材︽┏︹
   System.Drawing.Color changeColor =new System.Drawing.Color();
   
   System.Drawing.Color FirstColor =new System.Drawing.Color();
   FirstColor =System.Drawing.Color.LightBlue;
   System.Drawing.Color SecondColor =new System.Drawing.Color();
   SecondColor =System.Drawing.Color.White;
   int i=1;
   if (cc >0)
    dg.Items[i-1].BackColor =FirstColor;
   //   if (dg.ItemStyle ==dg.AlternatingItemStyle )
   // dg.Items[1].BackColor = Color.Black;
   int match = 0;
   while(i<cc)
   {
    //耞琌┮Τ﹚逆常
    foreach (int tmp in Col){
     //ňゎ肚逆index禬龟悔逆计,璶暗耞,禬碞┛菠ぃ瞶ウ
     if (tmp < cc) {
      if (dg.Items[i].Cells[tmp].Text != dg.Items[i-1].Cells[tmp].Text){
       match = 0;
       break;
      }
     }
     match = 1;
    }
    //狦﹚逆场常で皌玥讽玡︽籔玡︽肅︹,玥э跑肅︹
    if (match == 1)
    {
     dg.Items[i].BackColor = dg.Items[i-1].BackColor;
    }
    else
    {
     dg.Items[i].BackColor =changeColor;
    }
    if (dg.Items[i].BackColor==FirstColor)
     changeColor=SecondColor;
    else
     changeColor=FirstColor;

    i =i+1;
   }
  }
  #endregion

  /// <summary>
  /// 更计沮client狠
  /// </summary>
  /// <param name="response"></param>
  /// <param name="path"></param>
  /// <param name="realFilename"></param>
  /// <param name="VirtualName"></param>
  public static void DownLoadToClient(System.Web.HttpResponse response, string filepath, string VirtualName) {
//   if(realFilename.Trim()=="") {
//    response.Write("<script>alert('Invalid filename!');</script>");
//    return;
//   }
//
   try {
    if(File.Exists(filepath)) {
     FileInfo fi=new FileInfo(filepath);
     response.Clear();
     response.ClearHeaders();
     response.Buffer=false;
                                                             
     response.AppendHeader("Content-Disposition","attachment;filename="+System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(VirtualName)));
     response.AppendHeader("Content-Length",fi.Length.ToString());
     response.ContentType="application/octet-stream";
     response.WriteFile(filepath);
     response.Flush();

     response.End();
    }
   }
   catch(Exception){}
  }

 }
}

posted on 2007-05-08 22:06  大李  阅读(1795)  评论(0)    收藏  举报

导航

立博名家