예제 #1
0
        private void Readjc(string path)
        {
            IWorkbook wb = WorkbookFactory.Create(path);

            int count = 0;

            //循环 sheet
            for (int i = 0; i < wb.NumberOfSheets; i++)
            {
                //只处理第一个 sheet
                if (i == 0)
                {
                    ISheet ist = wb.GetSheetAt(i);
                    int rowofPage = ist.LastRowNum + 1;

                    for (int j = 3; j < rowofPage; j++)
                    {
                        count++;
                        IRow irow = ist.GetRow(j);

                        if (irow == null) continue;
                        if (irow.Cells.Count < 14) continue;

                        string traderName = irow.GetCell(11, MissingCellPolicy.RETURN_NULL_AND_BLANK).StringCellValue.Trim();
                        if (traderName.Length < 2) continue;
                        try
                        {
                            int keyno = gMaoYiShangDic[traderName];
                            gMaoYiShangDic[traderName]++;

                        }
                        catch (KeyNotFoundException ee)
                        {
                            gMaoYiShangDic.Add(traderName, 0);
                        }

                        string factoryName = getCellString(12, irow);
                        string factoryNameZip = stringZip(factoryName);

                        string add = getCellString(15, irow);
                        if (factoryName.Length < 2) continue;

                        //把工厂和贸易商联系起来的 一个冗余字典
                        if (gGongChangDic.ContainsKey(factoryName) == false)
                        {
                            gGongChangDic.Add(factoryName, traderName);

                            CainzFactory factory = new CainzFactory();
                            factory.FactoryName = factoryName;
                            //factory.FactoryNo = DateTime.Now.ToString("yyMMddHHmmss");
                            factory.FactoryAddress = getCellString(15, irow);
                            factory.Contact = getCellString(13, irow);
                            factory.ContactPhone = getCellString(14, irow);
                            FACTORYS.Add(factory);

                        }
                        if (gGongChangDic.ContainsKey(factoryNameZip) == false)
                        {
                            gGongChangDic.Add(factoryNameZip, traderName);
                        }

                    }

                }
            }
        }
예제 #2
0
        private void btnImportFactory_Click(object sender, EventArgs e)
        {
            using (var db = PublicDB.getDB())
            {
                foreach (var f in this.FACTORYS)
                {
                    string FactoryName = f.FactoryName;
                    entity.CainzFactory factory = db.CainzFactory.FirstOrDefault(item => item.FactoryName == FactoryName);
                    if (factory == null)
                    {
                        entity.CainzFactory _factory =new CainzFactory();
                        _factory.FactoryID=Guid.NewGuid();
                        _factory.FactoryName = FactoryName;
                        _factory.FactoryNameJP = Pinyin.GetInitials(f.FactoryName);
                        _factory.Deleted = 0;
                        _factory.CreateTime = DateTime.Now;

                        entity.CainzTrader ct = GetTraaterByFactoryName(_factory.FactoryName);

                        if (ct != null)
                        {
                            _factory.CainzTraderTraderID = ct.TraderID;
                            _factory.TraderID = ct.TraderID;
                            _factory.TraderName = ct.TraderName;
                            db.CainzFactory.Add(_factory);
                        }
                    }
                }
                db.SaveChanges();
            }
        }