Example #1
0
        private object[] GetAllItem()
        {
            try
            {
                string fileName = string.Empty;

                if (this.ViewState["UploadedFileName"] == null)
                {
                    BenQGuru.eMES.Common.ExceptionManager.Raise(this.GetType().BaseType, "$Error_UploadFileIsEmpty");
                }
                fileName = this.ViewState["UploadedFileName"].ToString();

                //原来的逻辑,读取CSV文件
                //string configFile = this.getParseConfigFileName();
                //BenQGuru.eMES.Web.Helper.DataFileParser parser = new BenQGuru.eMES.Web.Helper.DataFileParser();
                //parser.FormatName = "SMTFeederMaterial";
                //parser.ConfigFile = configFile;
                //items = parser.Parse(fileName);

                ArrayList columnList = new ArrayList();

                //定义变量,用来取多语言
                string sscode         = string.Empty; // 产线代码
                string itemcode       = string.Empty; // 产品代码
                string machine        = string.Empty; // 机台代码
                string machineStation = string.Empty; //站位
                string sourceMaterial = string.Empty; // 首选料
                string materialCode   = string.Empty; // 物料代码
                string feeder         = string.Empty; // Feeder规格编码
                string qty            = string.Empty;
                string table          = string.Empty;

                //读取XML文件取出字段键值对
                string    xmlPath    = this.Request.MapPath("") + @"\ImportSMTReelData.xml";
                string    dataType   = "ImportSMTReel";
                ArrayList lineValues = new ArrayList();
                lineValues = GetXMLHeader(xmlPath, dataType);

                for (int i = 0; i < lineValues.Count; i++)
                {
                    DictionaryEntry dictonary = new DictionaryEntry();
                    dictonary = (DictionaryEntry)lineValues[i];

                    if (dictonary.Key.ToString().ToUpper().Equals("SSCODE"))
                    {
                        sscode = dictonary.Value.ToString().ToUpper();
                        columnList.Add(sscode);
                    }
                    if (dictonary.Key.ToString().ToUpper().Equals("ITEMCODE"))
                    {
                        itemcode = dictonary.Value.ToString().ToUpper();
                        columnList.Add(itemcode);
                    }
                    if (dictonary.Key.ToString().ToUpper().Equals("MACHINECODE"))
                    {
                        machine = dictonary.Value.ToString().ToUpper();
                        columnList.Add(machine);
                    }
                    if (dictonary.Key.ToString().ToUpper().Equals("MACHINESTATIONCODE"))
                    {
                        machineStation = dictonary.Value.ToString().ToUpper();
                        columnList.Add(machineStation);
                    }
                    if (dictonary.Key.ToString().ToUpper().Equals("SOURCEMATERIALCODE"))
                    {
                        sourceMaterial = dictonary.Value.ToString().ToUpper();
                        columnList.Add(sourceMaterial);
                    }
                    if (dictonary.Key.ToString().ToUpper().Equals("MATERIALCODE"))
                    {
                        materialCode = dictonary.Value.ToString().ToUpper();
                        columnList.Add(materialCode);
                    }
                    if (dictonary.Key.ToString().ToUpper().Equals("FEEDERSPECCODE"))
                    {
                        feeder = dictonary.Value.ToString().ToUpper();
                        columnList.Add(feeder);
                    }
                    if (dictonary.Key.ToString().ToUpper().Equals("QTY"))
                    {
                        qty = dictonary.Value.ToString().ToUpper();
                        columnList.Add(qty);
                    }
                    if (dictonary.Key.ToString().ToUpper().Equals("PCBTABLE"))
                    {
                        table = dictonary.Value.ToString().ToUpper();
                        columnList.Add(table);
                    }
                }

                ////读取EXCEL格式文件
                //System.Data.DataTable dt = new DataTable();
                //try
                //{
                //    dt = GetExcelData(fileName);
                //}
                //catch (Exception)
                //{
                //    ExceptionManager.Raise(this.GetType().BaseType, "$GetExcelDataFiledCheckTemplate");
                //}

                //读取EXCEL格式文件
                System.Data.DataTable dt = new DataTable();
                try
                {
                    ImportXMLHelper xmlHelper         = new ImportXMLHelper(xmlPath, dataType);
                    ArrayList       gridBuilder       = new ArrayList();
                    ArrayList       notAllowNullField = new ArrayList();

                    gridBuilder       = xmlHelper.GetGridBuilder(this.languageComponent1, dataType);
                    notAllowNullField = xmlHelper.GetNotAllowNullField(this.languageComponent1);

                    ImportExcel imXls = new ImportExcel(fileName, dataType, gridBuilder, notAllowNullField);
                    dt = imXls.XlaDataTable;
                    //  dt = GetExcelData(fileName);
                }
                catch (Exception)
                {
                    ExceptionManager.Raise(this.GetType().BaseType, "$GetExcelDataFiledCheckTemplate");
                }

                //检查当前读入字段格式是否与当前登录语言相同
                CheckTemplateRight(dt, columnList);

                if ((dt != null) && (dt.Rows.Count > 0))
                {
                    for (int h = 0; h < dt.Rows.Count; h++)
                    {
                        //modified by kathy @20130813 产品代码缺少输入也要提示
                        //if (dt.Rows[h][itemcode].ToString() != string.Empty)
                        //{
                        SMTFeederMaterial material = new SMTFeederMaterial();
                        material.ProductCode        = dt.Rows[h][itemcode].ToString().ToUpper();
                        material.StepSequenceCode   = dt.Rows[h][sscode].ToString().ToUpper();
                        material.MachineCode        = dt.Rows[h][machine].ToString().ToUpper();
                        material.SourceMaterialCode = dt.Rows[h][sourceMaterial].ToString().ToUpper();
                        material.MachineStationCode = dt.Rows[h][machineStation].ToString().ToUpper();
                        material.MaterialCode       = dt.Rows[h][materialCode].ToString().ToUpper();
                        material.FeederSpecCode     = dt.Rows[h][feeder].ToString().ToUpper();
                        if (dt.Rows[h][qty].ToString() != string.Empty)
                        {
                            material.Qty = Decimal.Parse(dt.Rows[h][qty].ToString());
                        }
                        material.TableGroup = dt.Rows[h][table].ToString().ToUpper();
                        if (material.TableGroup == string.Empty)
                        {
                            material.TableGroup = "A";
                        }
                        list.Add(material);
                        //}
                    }
                }

                items = (SMTFeederMaterial[])list.ToArray(typeof(SMTFeederMaterial));
                CheckImportResult(items);


                ////原来的逻辑
                //if (items != null)
                //{
                //    for (int i = 0; i < items.Length; i++)
                //    {
                //        SMTFeederMaterial item = (SMTFeederMaterial)items[i];
                //        item.ProductCode = item.ProductCode.ToUpper();
                //        item.StepSequenceCode = item.StepSequenceCode.ToUpper();
                //        item.MachineCode = item.MachineCode.ToUpper();
                //        item.SourceMaterialCode = item.SourceMaterialCode.ToUpper();
                //        item.MachineStationCode = item.MachineStationCode.ToUpper();
                //        item.MaterialCode = item.MaterialCode.ToUpper();
                //        item.FeederSpecCode = item.FeederSpecCode.ToUpper();
                //        item.TableGroup = item.TableGroup.ToUpper();
                //        if (item.TableGroup == string.Empty)
                //            item.TableGroup = "A";
                //    }
                //    CheckImportResult(items);
                //}
            }
            catch (Exception e)
            {
                throw e;
            }

            return(items);
        }
Example #2
0
        private object[] GetAllMOByExcle()
        {
            try
            {
                string    fileName   = string.Empty;
                ArrayList columnList = new ArrayList();

                //定义变量,用来取多语言
                string factory       = string.Empty; // 工厂
                string mocode        = string.Empty; // 工单
                string itemcode      = string.Empty; // 产品代码
                string moType        = string.Empty; // 工单类型
                string moPlanQty     = string.Empty; // 工单计划数量
                string planSDate     = string.Empty; // 计划开始日期
                string planEDate     = string.Empty; // 计划完成日期
                string customerCode  = string.Empty; // 客户代码
                string customerOrder = string.Empty; // 客户单号
                string moMemo        = string.Empty;
                string moBOM         = string.Empty;

                string xmlPath  = this.Request.MapPath("") + @"\ImportMOData.xml";
                string dataType = "ImportMO";

                ArrayList lineValues = new ArrayList();
                lineValues = GetXMLHeader(xmlPath, dataType);

                for (int i = 0; i < lineValues.Count; i++)
                {
                    DictionaryEntry dictonary = new DictionaryEntry();
                    dictonary = (DictionaryEntry)lineValues[i];
                    if (dictonary.Key.ToString().Equals(MoDictionary.Factory))
                    {
                        factory = dictonary.Value.ToString().ToUpper();
                        columnList.Add(factory);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.Mocode))
                    {
                        mocode = dictonary.Value.ToString().ToUpper();
                        columnList.Add(mocode);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.Itemcode))
                    {
                        itemcode = dictonary.Value.ToString().ToUpper();
                        columnList.Add(itemcode);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.MoType))
                    {
                        moType = dictonary.Value.ToString().ToUpper();
                        columnList.Add(moType);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.MoPlanQty))
                    {
                        moPlanQty = dictonary.Value.ToString().ToUpper();
                        columnList.Add(moPlanQty);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.PlanSDate))
                    {
                        planSDate = dictonary.Value.ToString().ToUpper();
                        columnList.Add(planSDate);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.PlanEDate))
                    {
                        planEDate = dictonary.Value.ToString().ToUpper();
                        columnList.Add(planEDate);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.CustomerCode))
                    {
                        customerCode = dictonary.Value.ToString().ToUpper();
                        columnList.Add(customerCode);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.CustomerOrder))
                    {
                        customerOrder = dictonary.Value.ToString().ToUpper();
                        columnList.Add(customerOrder);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.MoMemo))
                    {
                        moMemo = dictonary.Value.ToString().ToUpper();
                        columnList.Add(moMemo);
                    }
                    if (dictonary.Key.ToString().Equals(MoDictionary.MoBOM))
                    {
                        moBOM = dictonary.Value.ToString().ToUpper();
                        columnList.Add(moBOM);
                    }
                }

                if (this.ViewState["UploadedFileName"] == null)
                {
                    BenQGuru.eMES.Common.ExceptionManager.Raise(this.GetType().BaseType, "$Error_UploadFileIsEmpty");
                }
                fileName = this.ViewState["UploadedFileName"].ToString();

                //读取EXCEL格式文件
                System.Data.DataTable dt = new DataTable();
                try
                {
                    ImportXMLHelper xmlHelper         = new ImportXMLHelper(xmlPath, dataType);
                    ArrayList       gridBuilder       = new ArrayList();
                    ArrayList       notAllowNullField = new ArrayList();

                    gridBuilder       = xmlHelper.GetGridBuilder(this.languageComponent1, dataType);
                    notAllowNullField = xmlHelper.GetNotAllowNullField(this.languageComponent1);

                    ImportExcel imXls = new ImportExcel(fileName, dataType, gridBuilder, notAllowNullField);
                    dt = imXls.XlaDataTable;
                    //  dt = GetExcelData(fileName);
                }
                catch (Exception)
                {
                    ExceptionManager.Raise(this.GetType().BaseType, "$GetExcelDataFiledCheckTemplate");
                }

                //对dt进行数据检查,去掉空行
                List <DataRow> removelist = new List <DataRow>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    bool rowdataisnull = true;
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (dt.Rows[i][j].ToString().Trim() != "")
                        {
                            rowdataisnull = false;
                        }
                    }
                    if (rowdataisnull)
                    {
                        removelist.Add(dt.Rows[i]);
                    }
                }
                for (int i = 0; i < removelist.Count; i++)
                {
                    dt.Rows.Remove(removelist[i]);
                }

                CheckTemplateRight(dt, columnList);

                DBDateTime dbDateTime = FormatHelper.GetNowDBDateTime(this.DataProvider);
                MOFacade   mofacade   = new MOFacade(this.DataProvider);
                ArrayList  objList    = new ArrayList();
                if ((dt != null) && (dt.Rows.Count > 0))
                {
                    for (int h = 0; h < dt.Rows.Count; h++)
                    {
                        MO mo = new MO();
                        try
                        {
                            //填充DOMAIN,这里不做Check
                            mo.MOCode   = FormatHelper.CleanString(dt.Rows[h][mocode].ToString().ToUpper());
                            mo.Factory  = FormatHelper.CleanString(dt.Rows[h][factory].ToString().ToUpper());
                            mo.ItemCode = FormatHelper.CleanString(dt.Rows[h][itemcode].ToString().ToUpper());
                            mo.MOType   = FormatHelper.CleanString(dt.Rows[h][moType].ToString().ToUpper());
                            try
                            {
                                mo.MOPlanQty = Convert.ToDecimal(FormatHelper.CleanString(dt.Rows[h][moPlanQty].ToString().ToUpper()));
                            }
                            catch (Exception)
                            {
                                ExceptionManager.Raise(this.GetType().BaseType, "$MOPlanQty_Must_Be_Decimal");
                                return(null);
                            }

                            mo.MOPlanStartTime = 0;
                            mo.MOPlanEndTime   = 0;
                            try
                            {
                                mo.MOPlanStartDate = FormatHelper.TODateInt(FormatHelper.CleanString(dt.Rows[h][planSDate].ToString().ToUpper()));
                                mo.MOPlanEndDate   = FormatHelper.TODateInt(FormatHelper.CleanString(dt.Rows[h][planEDate].ToString().ToUpper()));
                            }
                            catch (Exception)
                            {
                                ExceptionManager.Raise(this.GetType().BaseType, "$Data_Formart_Must_Be_YYYY-MM-DD");
                                return(null);
                            }

                            mo.CustomerCode    = FormatHelper.CleanString(dt.Rows[h][customerCode].ToString().ToUpper());
                            mo.CustomerOrderNO = FormatHelper.CleanString(dt.Rows[h][customerOrder].ToString().ToUpper());
                            mo.MOMemo          = FormatHelper.CleanString(dt.Rows[h][moMemo].ToString().ToUpper());
                            mo.BOMVersion      = FormatHelper.CleanString(dt.Rows[h][moBOM].ToString().ToUpper());

                            mo.MaintainUser = this.GetUserCode();
                            mo.MaintainDate = dbDateTime.DBDate;
                            mo.MaintainTime = dbDateTime.DBTime;

                            mo.MOInputQty        = 0;
                            mo.MORemark          = " ";
                            mo.MOScrapQty        = 0;
                            mo.MOActualQty       = 0;
                            mo.MOActualStartDate = 0;
                            mo.MOActualEndDate   = 0;
                            mo.MOStatus          = MOManufactureStatus.MOSTATUS_INITIAL;
                            mo.IDMergeRule       = 1;
                            mo.OrganizationID    = GlobalVariables.CurrentOrganizations.First().OrganizationID;
                            mo.MOPCBAVersion     = "1";
                            mo.MOVersion         = "1.0";
                            mo.MODownloadDate    = dbDateTime.DBDate; //当前时间
                            mo.IsControlInput    = "0";;
                            mo.IsBOMPass         = "******";
                            mo.MOUser            = this.GetUserCode();

                            objList.Add(mo);
                        }
                        catch (Exception ex)
                        {
                            ExceptionManager.Raise(this.GetType().BaseType, ex.Message);
                        }
                    }
                }
                moObjects = (MO[])objList.ToArray(typeof(MO));

                //检查当前数据是否符合导入要求(现在返回一个是否通过检查的标志)
                if (moObjects != null)
                {
                    foreach (MO mo in moObjects)
                    {
                        MODownloadCheck(mo);
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionManager.Raise(this.GetType().BaseType, e.Message);
            }

            return(moObjects);
        }