//protected override void gridWebGrid_ItemCommand(GridRecord row, string commandName)
        //{
        //    if (commandName == "Edit")
        //    {
        //        object obj = this.GetEditObject(row);
        //        if (obj != null)
        //        {
        //            this.SetEditObject(obj);
        //            this.buttonHelper.PageActionStatusHandle(PageActionType.Update);
        //        }
        //    }
        //    else if (commandName == "LinkDetail")
        //    {
        //        string pickNo = row.Items.FindItemByKey("PickNo").Text.Trim();
        //        //string storageOut = row.Items.FindItemByKey("StorageOut").Text.Trim();
        //        Response.Redirect(this.MakeRedirectUrl("FCreatePickLineMP.aspx", new string[] { "ACT", "PickNo" }, new string[] { "LinkDetail", pickNo }));
        //    }
        //}



        protected override void cmdExport_Click(object sender, EventArgs e)
        {
            BenQGuru.eMES.Material.WarehouseFacade _WarehouseFacade = new BenQGuru.eMES.Material.WarehouseFacade(base.DataProvider);

            List <string> ca = new List <string>();

            XlsPackage xls  = new XlsPackage();
            IFont      font = xls.Black;

            font.FontHeightInPoints = 10;
            ICellStyle style = xls.Normal;

            style.SetFont(font);

            xls.CreateSheet("IQC明细表");
            xls.NewRow(0);
            xls.Cell(0, "IQC单号", style);
            xls.Cell(1, "SAP单据号", style);
            //xls.Cell(2, "SAP单据号", style);
            xls.Cell(2, "入库类型", style);
            xls.Cell(3, "库位", style);
            xls.Cell(4, "供应商代码", style);
            xls.Cell(5, "供应商名称", style);
            xls.Cell(6, "鼎桥物料编码", style);
            xls.Cell(7, "供应商物料编码", style);
            xls.Cell(8, "鼎桥物料描述", style);
            xls.Cell(9, "检验方式", style);
            xls.Cell(10, "AQL标准", style);
            xls.Cell(11, "来料数量", style);
            xls.Cell(12, "样本数量", style);
            xls.Cell(13, "缺陷品数", style);
            xls.Cell(14, "退换货数量", style);
            xls.Cell(15, "现场整改数量", style);
            xls.Cell(16, "让步接收数量", style);
            xls.Cell(17, "特采放行数量", style);
            int cellNum = 18;
            SystemSettingFacade _SystemSettingFacade = new SystemSettingFacade(base.DataProvider);

            object[] objs = _SystemSettingFacade.GetErrorGroupcode();
            if (objs != null && objs.Length > 0)
            {
                foreach (ErrorCodeGroupA ecg in objs)
                {
                    xls.Cell(cellNum, ecg.ErrorCodeGroupDescription, style);
                    cellNum++;
                }
            }

            xls.Cell(cellNum++, "创建时间", style);

            xls.Cell(cellNum++, "QC检验完成时间", style);
            xls.Cell(cellNum++, "SQE判定完成时间", style);
            xls.Cell(cellNum++, "IQC检验完成时间", style);
            xls.Cell(cellNum++, "QC检验执行时间", style);
            xls.Cell(cellNum++, "SQE判定执行时间", style);
            xls.Cell(cellNum++, "IQC检验执行时间", style);



            int rowNum = 1;

            IQCDetailRecord[] iqcs = _WarehouseFacade.QueryIQCs(this.txtStorageCodeQuery.Text,
                                                                this.txtVendorCodeQuery.Text, this.drpStorageInTypeQuery.SelectedValue,
                                                                FormatHelper.TODateInt(dateInDateFromQuery.Text),
                                                                FormatHelper.TODateInt(dateInDateToQuery.Text));

            InventoryFacade _InventoryFacade = new InventoryFacade(base.DataProvider);


            for (int i = 0; i < iqcs.Length; i++)
            {
                xls.NewRow(rowNum);
                string iqcNO = iqcs[i].IQCNO;
                xls.Cell(0, iqcNO, style);
                string invNo = iqcs[i].INVNO;
                xls.Cell(1, invNo, style);
                string stType = iqcs[i].STTYPE;
                xls.Cell(2, stType, style);
                string StorageCode = iqcs[i].StorageCode;
                xls.Cell(3, StorageCode, style);
                string VENDORCODE = iqcs[i].VENDORCODE;
                xls.Cell(4, VENDORCODE, style);
                string VendorName = iqcs[i].VendorName;
                xls.Cell(5, VendorName, style);
                string DQMCODE = iqcs[i].DQMCODE;
                xls.Cell(6, DQMCODE, style);
                string VENDORMCODE = iqcs[i].VENDORMCODE;
                xls.Cell(7, VENDORMCODE, style);

                Domain.MOModel.Material m = (Domain.MOModel.Material)_InventoryFacade.GetMaterialByDQMCode(iqcs[i].DQMCODE);

                string MDESC = m.MchlongDesc;
                xls.Cell(8, MDESC, style);
                string IQCTYPE = iqcs[i].IQCTYPE;
                xls.Cell(9, IQCTYPE, style);
                string AQLLEVEL = iqcs[i].AQLLEVEL;
                xls.Cell(10, AQLLEVEL, style);
                string QTY = iqcs[i].QTY.ToString();
                xls.Cell(11, QTY, style);
                string IQCQTY = iqcs[i].SAMPLESIZE.ToString();
                xls.Cell(12, IQCQTY, style);
                string NGQTY = iqcs[i].NGQTY.ToString();
                xls.Cell(13, NGQTY, style);
                string RETURNQTY = iqcs[i].RETURNQTY.ToString();
                xls.Cell(14, RETURNQTY, style);
                string ReformQTY = iqcs[i].ReformQTY.ToString();
                xls.Cell(15, ReformQTY, style);
                string GiveQTY = iqcs[i].GiveQTY.ToString();
                xls.Cell(16, GiveQTY, style);
                string AcceptQTY = iqcs[i].AcceptQTY.ToString();
                xls.Cell(17, AcceptQTY, style);
                int cellNum2 = 18;
                if (objs != null && objs.Length > 0)
                {
                    foreach (ErrorCodeGroupA ecg in objs)
                    {
                        int num = _WarehouseFacade.GetErrorGroupNum(iqcs[i].IQCNO, ecg.ErrorCodeGroup);
                        xls.Cell(cellNum2, num, style);
                        cellNum2++;
                    }
                }
                string CDATE = iqcs[i].CDATE.ToString();
                xls.Cell(cellNum2++, CDATE, style);


                InvInOutTrans OCFinishInv  = _WarehouseFacade.QCFinishDateTimeTrans(iqcs[i].IQCNO);
                InvInOutTrans SQEFinishInv = _WarehouseFacade.SQEFinishDateTimeTrans(iqcs[i].IQCNO);
                InvInOutTrans IQCFinishInv = SQEFinishInv ?? (OCFinishInv ?? null);

                string QCFINISHDATEStr = OCFinishInv != null?FormatHelper.ToDateString(OCFinishInv.MaintainDate) : string.Empty;

                string SEQFINISHDATEStr = SQEFinishInv != null?FormatHelper.ToDateString(SQEFinishInv.MaintainDate) : string.Empty;

                string IQCFINISHDATEStr = IQCFinishInv != null?FormatHelper.ToDateString(IQCFinishInv.MaintainDate) : string.Empty;

                decimal QCDATERANGE = OCFinishInv != null?Common.Totalday(OCFinishInv.MaintainDate, OCFinishInv.MaintainTime, iqcs[i].CDATE, iqcs[i].CTIME) : (decimal)0;

                string IQCSEQDATERANGE = string.Empty;
                string IQCDATERANGEStr = string.Empty;
                if (OCFinishInv != null && SQEFinishInv != null)
                {
                    IQCSEQDATERANGE = Common.Totalday(SQEFinishInv.MaintainDate, SQEFinishInv.MaintainTime, OCFinishInv.MaintainDate, OCFinishInv.MaintainTime).ToString();
                }


                if (IQCFinishInv != null)
                {
                    IQCDATERANGEStr = Common.Totalday(IQCFinishInv.MaintainDate, IQCFinishInv.MaintainTime, iqcs[i].CDATE, iqcs[i].CTIME).ToString();
                }



                xls.Cell(cellNum2++, QCFINISHDATEStr, style);


                xls.Cell(cellNum2++, SEQFINISHDATEStr, style);


                xls.Cell(cellNum2++, IQCFINISHDATEStr, style);



                xls.Cell(cellNum2++, QCDATERANGE.ToString(), style);


                xls.Cell(cellNum2++, IQCSEQDATERANGE, style);


                xls.Cell(cellNum2++, IQCDATERANGEStr, style);

                rowNum++;
            }



            string filename = string.Format("Export_{0}_{1}.{2}", FormatHelper.TODateInt(System.DateTime.Now).ToString(), FormatHelper.TOTimeInt(System.DateTime.Now).ToString(), "xls");
            string filepath = string.Format(@"{0}{1}", this.DownloadPhysicalPath, filename);



            FileStream file = new FileStream(filepath, FileMode.Create, FileAccess.ReadWrite);

            xls.Save(file);
            file.Close();

            DownLoadFile1(filename);
        }