Exemplo n.º 1
0
        public static DataSet ImportExcelFromFile(
            string filePath)
        {
            var result = DataSetHelper.CreateDataSet(filePath);

            return(result);
        }
Exemplo n.º 2
0
        public void SimpleCreateTest()
        {
            string tempFilePath = Path.GetTempFileName();

            {
                DataSet   ds  = new DataSet();
                DataTable dt1 = new DataTable("Table 1");
                dt1.Columns.Add("Column A", typeof(String));
                dt1.Columns.Add("Column B", typeof(String));
                dt1.Rows.Add("Test 1", "Test 2");
                dt1.Rows.Add("Test 3", "Test 4");
                ds.Tables.Add(dt1);

                DataTable dt2 = new DataTable("Table 2");
                ds.Tables.Add(dt2);

                DataTable dt3 = new DataTable("Table 3");
                dt3.Columns.Add("Column C", typeof(String));
                ds.Tables.Add(dt3);

                DataSetHelper.CreateWorkbook(tempFilePath, ds);
            }

            {
                DataSet ds = DataSetHelper.CreateDataSet(tempFilePath);
                Assert.AreEqual(3, ds.Tables.Count);
                Assert.AreEqual("Table 1", ds.Tables[0].TableName);
                Assert.AreEqual("Table 2", ds.Tables[1].TableName);
                Assert.AreEqual("Table 3", ds.Tables[2].TableName);

                Assert.AreEqual(2, ds.Tables[0].Columns.Count);
                Assert.AreEqual(1, ds.Tables[1].Columns.Count);
                Assert.AreEqual(1, ds.Tables[2].Columns.Count);
                Assert.AreEqual("Column A", ds.Tables[0].Columns[0].ColumnName);
                Assert.AreEqual("Column B", ds.Tables[0].Columns[1].ColumnName);
                Assert.AreEqual("Column C", ds.Tables[2].Columns[0].ColumnName);

                Assert.AreEqual(2, ds.Tables[0].Rows.Count);
                Assert.AreEqual(0, ds.Tables[1].Rows.Count);
                Assert.AreEqual(0, ds.Tables[2].Rows.Count);
                Assert.AreEqual("Test 1", ds.Tables[0].Rows[0][0]);
                Assert.AreEqual("Test 2", ds.Tables[0].Rows[0][1]);
                Assert.AreEqual("Test 3", ds.Tables[0].Rows[1][0]);
                Assert.AreEqual("Test 4", ds.Tables[0].Rows[1][1]);
            }
        }
Exemplo n.º 3
0
        public void BaseTest()
        {
            var producerName = Generator.Name();
            var clientId     = 0u;
            var supplier     = TestSupplier.CreateNaked(session);
            var producer     = new TestProducer(producerName);

            session.Save(producer);
            var product = new TestProduct("testProduct");

            session.Save(product);
            var price = supplier.Prices[0];

            price.Enabled       = true;
            price.AgencyEnabled = true;
            session.Save(price);

            var client = TestClient.CreateNaked(session);

            var core = new TestCore(price.AddProductSynonym(product))
            {
                Price    = price,
                Producer = producer,
                Quantity = "2",
                Code     = "2",
                Period   = ""
            };

            session.Save(core);

            var matrix = new TestMatrix();

            session.Save(matrix);

            var costId = new CostPrimaryKey {
                CoreId = core.Id,
                CostId = price.Costs[0].Id
            };
            var cost = new TestCost {
                Id   = costId,
                Cost = 10
            };

            session.Save(cost);

            var rule = client.Settings;

            rule.BuyingMatrix       = matrix;
            rule.BuyingMatrixAction = TestMatrixAction.Delete;
            rule.BuyingMatrixType   = TestMatrixType.BlackList;
            session.Save(rule);

            session.CreateSQLQuery(string.Format(@"
insert into farm.BuyingMatrix (PriceId, ProductId, MatrixId)
value
({0}, {1}, {2})", price.Id, product.Id, matrix.Id))
            .ExecuteUpdate();
            clientId = client.Id;

            Property("ClientCode", clientId);
            report = new Inforoom.ReportSystem.ByOffers.MatrixReport(Conn, properties);
            BuildOrderReport("Rep.xls");
            var resuleSet = DataSetHelper.CreateDataSet("Rep.xls").Tables[0];

            Assert.That(resuleSet.Rows[4][13], Does.Contain("Удаление предложения"));
            Assert.That(resuleSet.Rows[4][5], Does.Contain(producerName));
        }
Exemplo n.º 4
0
        private static void ExportBin(string filePath, string filename)
        {
            ByteArray ba = new ByteArray();

            Assembly asm = Assembly.LoadFile(Application.dataPath + "/../Library/ScriptAssemblies/Assembly-CSharp.dll");

            DataSet dataSet = DataSetHelper.CreateDataSet(filePath + filename + FILE_SUFFIX);

            if (dataSet != null)
            {
                //int sheetNum = dataSet.Tables.Count;

                int canreadSheet = 0;
                foreach (DataTable sheet in dataSet.Tables)
                {
                    string className = sheet.TableName;
                    object obj       = asm.CreateInstance(className);

                    //Debug.Log("当前表名是: " + sheet.TableName);
                    if (obj == null)
                    {
                        continue;
                    }
                    ++canreadSheet;
                }
                ba.writeInt(canreadSheet);
                //Converter.WriteInt(writer, sheetNum);
                foreach (DataTable sheet in dataSet.Tables)
                {
                    string className = sheet.TableName;
                    object obj       = asm.CreateInstance(className);
                    if (obj == null)
                    {
                        //MUtils.ShowNotice("Load data error: "+className+" in "+filePath+" has no data.");
                        continue;
                    }
                    FieldInfo[] fis = obj.GetType().GetFields();

                    ba.writeUTF(sheet.TableName);
                    //Converter.WriteJavaString(writer,sheet.TableName);

                    int rows     = sheet.Rows.Count;
                    int rowCount = 0;
                    for (int r = 0; r != rows; ++r)
                    {
                        if (string.IsNullOrEmpty(sheet.Rows[r].ItemArray[0].ToString()))
                        {
                            break;
                        }

                        rowCount++;
                    }
                    ba.writeInt(rowCount);
                    if (rows > 0)
                    {
                        ba.writeInt(sheet.Rows[0].ItemArray.Length);
                    }
                    else
                    {
                        ba.writeInt(0);
                    }

                    foreach (DataRow row in sheet.Rows)
                    {
                        int i = 0;
                        foreach (object item in row.ItemArray)
                        {
                            if (i >= fis.Length)
                            {
                                break;
                            }

                            if (fis[i].FieldType == typeof(int))
                            {
                                int val = 0;
                                int.TryParse(item.ToString(), out val);
                                ba.writeInt(val);
                            }
                            else if (fis[i].FieldType == typeof(short))
                            {
                                short val = 0;
                                short.TryParse(item.ToString(), out val);
                                ba.writeShort(val);
                            }
                            else if (fis[i].FieldType == typeof(long))
                            {
                                long val = 0;
                                long.TryParse(item.ToString(), out val);
                                ba.writeLong(val);
                            }
                            else if (fis[i].FieldType == typeof(float) || fis[i].FieldType == typeof(double) ||
                                     fis[i].FieldType == typeof(string))
                            {
                                ba.writeUTF(item.ToString());
                            }

                            ++i;
                        }
                    }
                }
            }

            //string binpath = AssetBundlePath.GetStreamingAssetsPath() + "bin/".Replace("file://","");
            string binpath = AssetBundlePath.GetStreamingAssetsPath().Replace("file://", "");

            binpath = binpath.Replace("file://", "");

            var file = new FileStream(binpath + filename + FILE_BIN_SUFFIX, FileMode.Create, System.IO.FileAccess.Write);

            byte[] bytes = ba.data;
            file.Write(bytes, 0, bytes.Length);
            file.Close();
        }