protected void btnAdd_ServerClick(Object sender, EventArgs e)
    {
        ITCNDCheckQCHoldDef item = new ITCNDCheckQCHoldDef();

        item.Code = this.dCode.Text.ToUpper().Trim();

        if (string.Compare(this.dIsHoldValue.Value, "Yes") == 0)
        {
            item.isHold = "1";
        }
        else if (string.Compare(this.dIsHoldValue.Value, "No") == 0)
        {
            item.isHold = "0";
        }
        else
        {
            showErrorMessage(pmtMessageSelectIsHold);
            return;
        }

        item.Descr = this.dDescr.Text.Trim();
        item.Editor = this.HiddenUserName.Value;
   
        try
        {
            iITCNDCheckQCHoldSetting.AddITCNDCheckQCHold(item);
        }
        catch (FisException ex)
        {
            showErrorMessage(ex.mErrmsg);
            return;
        }
        catch (Exception ex)
        {
            //show error
            showErrorMessage(ex.Message);
            return;
        }
        ShowList();
        String itemId = replaceSpecialChart(item.Code);
        this.updatePanel2.Update();
        ScriptManager.RegisterStartupScript(this.updatePanelAll, typeof(System.Object), "saveUpdate", "AddUpdateComplete('" + itemId + "');DealHideWait();", true);

    }
    protected void btnDelete_ServerClick(Object sender, EventArgs e)
    {
        //ITC-1361-0168, Jessica Liu, 2012-10-24
        //string oldCode = this.dOldCode.Value.ToUpper().Trim();
        string oldCode = this.dOldCode.Value.Trim();
        
        try
        {
            ITCNDCheckQCHoldDef item = new ITCNDCheckQCHoldDef();
            item.Code = oldCode;
            iITCNDCheckQCHoldSetting.DeleteITCNDCheckQCHold(item);
        }
        catch (FisException ex)
        {
            showErrorMessage(ex.mErrmsg);
            return;
        }
        catch (Exception ex)
        {
            //show error
            showErrorMessage(ex.Message);
            return;
        }

        ShowList();
        this.updatePanel2.Update();
        ScriptManager.RegisterStartupScript(this.updatePanelAll, typeof(System.Object), "saveUpdate", "DeleteComplete();DealHideWait();", true);
    }
        public void UpdateITCNDCheckQCHold(ITCNDCheckQCHoldDef obj)
        {
            try
            {
                IProductRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
                
                ITCNDCheckQCHoldDef tempInfo = new ITCNDCheckQCHoldDef();
                tempInfo.Code = obj.Code;
                ITCNDCheckQCHoldDef newItem = new ITCNDCheckQCHoldDef();
                newItem.Code = obj.Code;
                newItem.Editor = obj.Editor;
                newItem.Descr = obj.Descr;
                newItem.isHold = obj.isHold;
                newItem.Cdt = Convert.ToDateTime(obj.Cdt);
                newItem.Udt = DateTime.Now;
                itemRepository.ChangeITCNDCheckQCHold(newItem, tempInfo);
            }
            catch (Exception)
            {
                throw;
            }

        }
        public bool CheckExistITCNDCheckQCHold(ITCNDCheckQCHoldDef obj)
        {
            try
            {

                IProductRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
                ITCNDCheckQCHoldDef tempInfo = new ITCNDCheckQCHoldDef();
                tempInfo.Code = obj.Code;
                IList<ITCNDCheckQCHoldDef> exists = itemRepository.GetExistITCNDCheckQCHold(tempInfo);
                if (exists == null || exists.Count <= 0)
                {
                    return false;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return true;
        }
        /// <summary>
        /// 更新一条ITCNDCheckQCHold的记录数据(update), 若新Code与存在记录的Code的名称相同,则提示业务异常
        /// </summary>
        /// <param name="obj">更新ITCNDCheckQCHoldDef结构</param>
        /// <param name="oldCode">修改前Code</param>
        public void UpdateITCNDCheckQCHold(ITCNDCheckQCHoldDef obj, string oldCode)
        {
            try
            {
                IProductRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();

                //新Code与存在记录的Code的名称相同,则提示业务异常
                ITCNDCheckQCHoldDef tempNewInfo = new ITCNDCheckQCHoldDef();
                tempNewInfo.Code = obj.Code;
                IList<ITCNDCheckQCHoldDef> exists = itemRepository.GetExistITCNDCheckQCHold(tempNewInfo);
                if (exists != null && exists.Count > 0 && oldCode != obj.Code)
                {
                    List<string> erpara = new List<string>();
                    FisException ex;
                    ex = new FisException("DMT066", erpara);
                    throw ex;

                }

                ITCNDCheckQCHoldDef tempInfo = new ITCNDCheckQCHoldDef();
                tempInfo.Code = oldCode;
                IList<ITCNDCheckQCHoldDef> oldexists = itemRepository.GetExistITCNDCheckQCHold(tempInfo);
                if (oldexists == null || oldexists.Count <= 0)
                {
                    List<string> erpara = new List<string>();
                    FisException ex;
                    ex = new FisException("DMT082", erpara);
                    throw ex;

                }

                ITCNDCheckQCHoldDef newItem = new ITCNDCheckQCHoldDef();
                newItem.Code = obj.Code;
                newItem.Editor = obj.Editor;
                newItem.Descr = obj.Descr;
                newItem.isHold = obj.isHold;
                newItem.Cdt = Convert.ToDateTime(obj.Cdt);
                newItem.Udt = DateTime.Now;
                itemRepository.ChangeITCNDCheckQCHold(newItem, tempInfo);
            }
            catch (Exception)
            {
                throw;
            }

        }
 /// <summary>
 /// 删除一条ITCNDCheckQCHold的记录数据
 /// </summary>
 /// <param name="obj">ITCNDCheckQCHoldDef结构</param>
 public void DeleteITCNDCheckQCHold(ITCNDCheckQCHoldDef obj)
 {
     try
     {
         IProductRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
         itemRepository.RemoveITCNDCheckQCHold(obj);
     }
     catch (Exception)
     {
         throw;
     }
 }
        /// <summary>
        /// 保存一条ITCNDCheckQCHold的记录数据(Add), 若Code与存在记录的Code的名称相同,则提示业务异常
        /// </summary>
        /// <param name="obj">ITCNDCheckQCHoldDef结构</param>
        public void AddITCNDCheckQCHold(ITCNDCheckQCHoldDef obj)
        {
            try
            {
                IProductRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();

                //Code与存在记录的Code的名称相同,则提示业务异常
                ITCNDCheckQCHoldDef newObj = new ITCNDCheckQCHoldDef();
                newObj.Code = obj.Code;
                IList<ITCNDCheckQCHoldDef> exists = itemRepository.GetExistITCNDCheckQCHold(newObj);
                if (exists != null && exists.Count > 0)
                {
                    List<string> erpara = new List<string>();
                    FisException ex;
                    ex = new FisException("DMT066", erpara);
                    throw ex;

                }

                ITCNDCheckQCHoldDef newItem = new ITCNDCheckQCHoldDef();
                newItem.Code = obj.Code;
                newItem.Editor = obj.Editor;
                newItem.Descr = obj.Descr;
                newItem.isHold = obj.isHold;

                itemRepository.AddITCNDCheckQCHold(newItem);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 取得15天前ITCNDCheckQCHold记录(按Code栏位排序)
        /// </summary>
        /// <returns>ITCNDCheckQCHold记录列表(15天)</returns>
        public IList<ITCNDCheckQCHoldDef> GetITCNDCheckQCHoldListByDay()
        {
            List<ITCNDCheckQCHoldDef> retLst = new List<ITCNDCheckQCHoldDef>();

            try
            {
                IProductRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository>();
                IList<ITCNDCheckQCHoldDef> getData = itemRepository.GetITCNDCheckQCHoldList();

                if (getData != null)
                {
                    IList<ITCNDCheckQCHoldDef> ListByDay = (from q in getData
                                                            where q.Udt > DateTime.Now.AddDays(-15)
                                                            select q).ToList<ITCNDCheckQCHoldDef>();



                    for (int i = 0; i < ListByDay.Count; i++)
                    {
                        ITCNDCheckQCHoldDef data = ListByDay[i];
                        ITCNDCheckQCHoldDef item = new ITCNDCheckQCHoldDef();
                        item.Code = data.Code;
                        item.Descr = data.Descr;
                        item.Editor = data.Editor;
                        item.isHold = data.isHold;

                        /* 2012-5-14
                        if (data.Cdt == DateTime.MinValue)
                        {
                            item.Cdt = "";
                        }
                        else
                        {
                            item.Cdt = ((System.DateTime)data.Cdt).ToString("yyyy-MM-dd HH:mm:ss");
                        }

                        if (data.Udt == DateTime.MinValue)
                        {
                            item.Udt = "";
                        }
                        else
                        {
                            item.Udt = ((System.DateTime)data.Udt).ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        */
                        item.Cdt = (System.DateTime)data.Cdt;
                        item.Udt = (System.DateTime)data.Udt;

                        retLst.Add(item);
                    }
                }

                return retLst;
            }
            catch (Exception)
            {
                throw;
            }

        }
    protected void btnOK_ServerClick(Object sender, EventArgs e)
    {
        string fullFileName = "";
        try
        {
            DataTable dt = new DataTable();
            if (dFileUpload.FileName.Trim() == "")
            {
                pmtMessage4 = this.GetLocalResourceObject(Pre + "_pmtMessage4").ToString();
                showErrorMessage(pmtMessage4);
                return;
            }            
            if (dFileUpload.HasFile)
            {
                string fileName = dFileUpload.FileName;
                string filePath = HttpContext.Current.Server.MapPath("~");
                string path = filePath + "\\tmp";                
                //根下tmp目录存上传临时文件
                MakeDirIfNotExist(path);                
                try
                {
                    string extName = fileName.Substring(fileName.LastIndexOf("."));
                    //if (extName != ".xls")
                    //{
                    //    pmtMessage2 = this.GetLocalResourceObject(Pre + "_pmtMessage2").ToString();
                    //    showErrorMessage(pmtMessage2);
                    //    return;
                    //}
                    ////////////////////
                    Guid guid = System.Guid.NewGuid();
                    fullFileName = path + "\\" + guid.ToString() + extName;
                    dFileUpload.PostedFile.SaveAs(fullFileName);
                    dt = ExcelManager.getExcelSheetData(fullFileName);
                }
                catch
                {
                    pmtMessage2 = this.GetLocalResourceObject(Pre + "_pmtMessage2").ToString();
                    showErrorMessage(pmtMessage2);
                    return;
                }
                int startRow = EXCEL_DATA_START_ROW;
                int endRow = dt.Rows.Count + startRow;
                if (endRow < startRow)
                {
                    pmtMessage3 = this.GetLocalResourceObject(Pre + "_pmtMessage3").ToString();                    
                    showErrorMessage(pmtMessage3);
                    return;
                }

                List<ITCNDCheckQCHoldDef> importList = new List<ITCNDCheckQCHoldDef>();
                int iRowsCountNPOI = dt.Rows.Count;
                Dictionary<string, string> CodeInList = new Dictionary<string, string>();
                List<string> Descr = new List<string>();

                for (int iRow = 1; iRow < iRowsCountNPOI; iRow++)
                {
                    int lineNum = iRow + EXCEL_DATA_START_ROW - 1;
                    string Code = dt.Rows[iRow][0].ToString();
                    string Ishold = dt.Rows[iRow][1].ToString();
                    string DescrValue = dt.Rows[iRow][2].ToString();
                    if (Code == "" && Ishold == "" && DescrValue == "")
                    {
                        continue;
                    }
                    if (Code == "" || Ishold == "" || DescrValue == "")
                    {
                        pmtMessage5= this.GetLocalResourceObject(Pre + "_pmtMessage5").ToString();
                        string tmpMessage = pmtMessage5 + " " + lineNum.ToString();
                        showErrorMessage(tmpMessage);
                        return;
                    }
                    if (Ishold != "Yes" && Ishold != "No")
                    {
                        pmtMessage5 = this.GetLocalResourceObject(Pre + "_pmtMessage5").ToString();
                        string tmpMessage = pmtMessage5 + " " + lineNum.ToString();
                        showErrorMessage(tmpMessage);
                        return;
                    }
                    if (CodeInList.ContainsKey(Code) == false)
                    {
                        CodeInList.Add(Code, Ishold);
                        Descr.Add(DescrValue);
                    }
                    else
                    {
                        //int currentNum = modelInList[Value1NPOI] + outValue;
                        //modelInList[Value1NPOI] = currentNum;
                        showErrorMessage("上傳資料重複:第" + lineNum + "行,『" + Code + "』");
                        return;
                    }
                }
                int count = 0;
                foreach (KeyValuePair<string, string> kvp in CodeInList)
                {
                    ITCNDCheckQCHoldDef item = new ITCNDCheckQCHoldDef();

                    item.Code = kvp.Key;
                    item.isHold = kvp.Value == "Yes" ? "1" : "0";
                    item.Descr = Descr[count];
                    item.Editor = this.HiddenUserName.Value;
                    item.Cdt = DateTime.Now;
                    item.Udt = DateTime.Now;
                    //SpecialOrderInfo item = new SpecialOrderInfo();
                    //SpecialOrderStatus Status = SpecialOrderStatus.Created;
                    //item.
                    //item.FactoryPO = kvp.Key;
                    //item.Qty = kvp.Value;
                    //item.AssetTag = Assettag[count];
                    //item.Editor = this.HiddenUserName.Value;
                    
                    //item.Status = Status;
                    //item.Remark = "";
                    importList.Add(item);
                    count++;
                }
                if (importList.Count < 1)
                {
                    pmtMessage3 = this.GetLocalResourceObject(Pre + "_pmtMessage3").ToString();
                    showErrorMessage(pmtMessage3);
                    return;
                }
                foreach (ITCNDCheckQCHoldDef ItemInfo in importList)
                {
                    if (iITCNDCheckQCHoldSetting.CheckExistITCNDCheckQCHold(ItemInfo))
                    {
                        //update
                        iITCNDCheckQCHoldSetting.UpdateITCNDCheckQCHold(ItemInfo);
                    }
                    else
                    { 
                        //add
                        iITCNDCheckQCHoldSetting.AddITCNDCheckQCHold(ItemInfo);
                    }
                }
                

                //IList<string> List = iITCNDCheckQCHoldSetting.ch(importList);
                //string dataString="";
                //ListToString(List, ref dataString);
                //this.dUploadTableResultData.Value = dataString;
            }
            else
            {
                pmtMessage2 = this.GetLocalResourceObject(Pre + "_pmtMessage2").ToString();
                showErrorMessage(pmtMessage2);
                return;
            }
        }
        catch (FisException ex)
        {
            showErrorMessage(ex.mErrmsg);
            return;
        }
        catch (Exception ex)
        {
            //show error
            showErrorMessage(ex.Message);
            return;
        }
        finally
        {
            TryDeleteTempFile(fullFileName);
        }
        ScriptManager.RegisterStartupScript(this.updatePanelAll, typeof(System.Object), "OKComplete", "OKComplete();DealHideWait();", true);
    }