Beispiel #1
0
 public Kecamatan(string name, Kota kota)
 {
     this.RawName = name;
     this.JneRate = new JNERate2(this);
     this.Name    = GetDisplayName(name, kota);
     this.Kota    = kota;
 }
 public Kecamatan(string name, Kota kota)
 {
     this.RawName = name;
     this.JneRate = new JNERate2(this);
     this.Name = GetDisplayName(name, kota);
     this.Kota = kota;
 }
        public void Parse(string filePath, IList<Province> ProvinseList)
        {
            FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
            //...
            //1. Reading from a binary Excel file ('97-2003 format; *.xls)
            IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            //...
            //3. DataSet - The result of each spreadsheet will be created in the result.Tables
            DataSet result = excelReader.AsDataSet();

            //5. Data Reader methods
            Province currentProvince = null;

            var row = 0;
            var l = new List<string>();
            while (excelReader.Read())
            {
                //for (var i = 0; i < excelReader.FieldCount; ++i)
                //{
                //    l.Add(excelReader.GetString(i));
                //}
                //Console.WriteLine(string.Join(",", l));

                var NoPropinsi = excelReader.GetString(NoPropinsiColumnIndex);
                var Propinse = excelReader.GetString(PropinsiColumnIndex);
                var KotaMadyaOrKabupaten = excelReader.GetString(KotamadyaOrKabupatenColumnIndex);
                var kecamatan = excelReader.GetString(KecamatanColumnIndex);
                var Harga = excelReader.GetString(HargaColumnIndex);
                var HargaOther = excelReader.FieldCount >= HargaOtherColumnIndex ? excelReader.GetString(HargaOtherColumnIndex) : Harga;

                int j = 0;
                if (!string.IsNullOrEmpty(NoPropinsi) && Int32.TryParse(NoPropinsi, out j) && !string.IsNullOrEmpty(Propinse))
                {
                    Propinse = Propinse.Trim();

                    if (!ProvinseList.Any(p => p.Is(Propinse)))
                    {
                        var provinse = new Province(Propinse);
                        currentProvince = provinse;
                        ProvinseList.Add(provinse);
                    }
                    else
                    {
                        currentProvince = ProvinseList.First(p => p.Is(Propinse));
                    }
                }
                else if (!string.IsNullOrEmpty(Propinse))
                {
                    if (currentProvince != null)
                    {
                        currentProvince = ProvinseList.First(p => p.Is(Propinse));
                    }
                }

                if (!string.IsNullOrEmpty(KotaMadyaOrKabupaten) || !string.IsNullOrEmpty(kecamatan))
                {
                    if (currentProvince != null)
                    {

                        var kotaName = !string.IsNullOrEmpty(KotaMadyaOrKabupaten) ? KotaMadyaOrKabupaten : kecamatan;
                        kotaName = kotaName.Trim();
                        kecamatan = kecamatan.Trim();
                        Kota kotaObject = new Kota(kotaName, kecamatan, currentProvince);

                        if (!currentProvince.KotaList.Any(k => k.Equals(kotaObject)))
                        {
                            currentProvince.KotaList.Add(kotaObject);
                        }
                        else
                        {
                            kotaObject = currentProvince.KotaList.First(k => k.Equals(kotaObject));
                        }

                        kotaObject.FirstKecamatan = kecamatan;

                        if (!string.IsNullOrWhiteSpace(HargaOther) || !string.IsNullOrWhiteSpace(Harga))
                        {
                            var otherHarga = !string.IsNullOrWhiteSpace(HargaOther) ? HargaOther : Harga;
                            if (this.RateType == JNERateType.REG)
                            {
                                kotaObject.JneRate.RegulerRate = decimal.Parse(Harga);
                                kotaObject.JneRate.OtherRegulerRate = decimal.Parse(otherHarga);
                            }
                            else if (this.RateType == JNERateType.OKE)
                            {
                                kotaObject.JneRate.OkeRate = decimal.Parse(Harga);
                                kotaObject.JneRate.OtherOkeRate = decimal.Parse(otherHarga);
                            }
                        }
                    }
                }

                row++;
            }

            //6. Free resources (IExcelDataReader is IDisposable)
            excelReader.Close();
        }
        public void Parse(string filePath, IList <Province> ProvinseList)
        {
            FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
            //...
            //1. Reading from a binary Excel file ('97-2003 format; *.xls)
            IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            //...
            //3. DataSet - The result of each spreadsheet will be created in the result.Tables
            DataSet result = excelReader.AsDataSet();

            //5. Data Reader methods
            Province currentProvince = null;

            var row = 0;
            var l   = new List <string>();

            while (excelReader.Read())
            {
                //for (var i = 0; i < excelReader.FieldCount; ++i)
                //{
                //    l.Add(excelReader.GetString(i));
                //}
                //Console.WriteLine(string.Join(",", l));

                var NoPropinsi           = excelReader.GetString(NoPropinsiColumnIndex);
                var Propinse             = excelReader.GetString(PropinsiColumnIndex);
                var KotaMadyaOrKabupaten = excelReader.GetString(KotamadyaOrKabupatenColumnIndex);
                var kecamatan            = excelReader.GetString(KecamatanColumnIndex);
                var Harga      = excelReader.GetString(HargaColumnIndex);
                var HargaOther = excelReader.FieldCount >= HargaOtherColumnIndex?excelReader.GetString(HargaOtherColumnIndex) : Harga;

                int j = 0;
                if (!string.IsNullOrEmpty(NoPropinsi) && Int32.TryParse(NoPropinsi, out j) && !string.IsNullOrEmpty(Propinse))
                {
                    Propinse = Propinse.Trim();


                    if (!ProvinseList.Any(p => p.Is(Propinse)))
                    {
                        var provinse = new Province(Propinse);
                        currentProvince = provinse;
                        ProvinseList.Add(provinse);
                    }
                    else
                    {
                        currentProvince = ProvinseList.First(p => p.Is(Propinse));
                    }
                }
                else if (!string.IsNullOrEmpty(Propinse))
                {
                    if (currentProvince != null)
                    {
                        currentProvince = ProvinseList.First(p => p.Is(Propinse));
                    }
                }

                if (!string.IsNullOrEmpty(KotaMadyaOrKabupaten) || !string.IsNullOrEmpty(kecamatan))
                {
                    if (currentProvince != null)
                    {
                        var kotaName = !string.IsNullOrEmpty(KotaMadyaOrKabupaten) ? KotaMadyaOrKabupaten : kecamatan;
                        kotaName  = kotaName.Trim();
                        kecamatan = kecamatan.Trim();
                        Kota kotaObject = new Kota(kotaName, kecamatan, currentProvince);

                        if (!currentProvince.KotaList.Any(k => k.Equals(kotaObject)))
                        {
                            currentProvince.KotaList.Add(kotaObject);
                        }
                        else
                        {
                            kotaObject = currentProvince.KotaList.First(k => k.Equals(kotaObject));
                        }

                        kotaObject.FirstKecamatan = kecamatan;

                        if (!string.IsNullOrWhiteSpace(HargaOther) || !string.IsNullOrWhiteSpace(Harga))
                        {
                            var otherHarga = !string.IsNullOrWhiteSpace(HargaOther) ? HargaOther : Harga;
                            if (this.RateType == JNERateType.REG)
                            {
                                kotaObject.JneRate.RegulerRate      = decimal.Parse(Harga);
                                kotaObject.JneRate.OtherRegulerRate = decimal.Parse(otherHarga);
                            }
                            else if (this.RateType == JNERateType.OKE)
                            {
                                kotaObject.JneRate.OkeRate      = decimal.Parse(Harga);
                                kotaObject.JneRate.OtherOkeRate = decimal.Parse(otherHarga);
                            }
                        }
                    }
                }

                row++;
            }

            //6. Free resources (IExcelDataReader is IDisposable)
            excelReader.Close();
        }
        public void Parse(string filePath, IList<Province> ProvinceList)
        {
            FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
            //...
            //1. Reading from a binary Excel file ('97-2003 format; *.xls)
            IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            //...
            //3. DataSet - The result of each spreadsheet will be created in the result.Tables
            DataSet result = excelReader.AsDataSet();

            //5. Data Reader methods
            Province currentProvince = null;
            Kota currentKota = null;
            var row = 0;
            var l = new List<string>();
            while (excelReader.Read())
            {

                var ProvinceName = excelReader.GetString(PropinsiColumnIndex);
                var KotaMadyaOrKabupatenName = excelReader.GetString(KotamadyaOrKabupatenColumnIndex);
                var KecamatanName = excelReader.GetString(KecamatanColumnIndex);
                if (row >= 9)
                {
                    int j = 0;
                    if (!string.IsNullOrWhiteSpace(ProvinceName) && String.IsNullOrEmpty(KotaMadyaOrKabupatenName) &&
                        string.IsNullOrEmpty(KecamatanName))
                    {
                        if (
                            !ProvinceList.Any(
                                p => String.Equals(p.Name, ProvinceName, StringComparison.InvariantCultureIgnoreCase)))
                        {

                            ProvinceList.Add(new Province(ProvinceName));
                        }
                        var Propinsi = ProvinceList.First(
                            p => String.Equals(p.Name, ProvinceName, StringComparison.InvariantCultureIgnoreCase));
                        currentProvince = Propinsi;
                    }
                    else if (string.IsNullOrWhiteSpace(ProvinceName) && !String.IsNullOrEmpty(KotaMadyaOrKabupatenName) &&
                             string.IsNullOrEmpty(KecamatanName))
                    {
                        if (currentProvince != null)
                        {
                            if (
                                !currentProvince.KotaList.Any(
                                    k =>
                                    string.Equals(k.RawName, KotaMadyaOrKabupatenName,
                                                  StringComparison.CurrentCultureIgnoreCase)))
                            {
                                var kota = new Kota(KotaMadyaOrKabupatenName, string.Empty, currentProvince);
                                currentProvince.KotaList.Add(kota);
                            }
                            currentKota =
                                currentProvince.KotaList.First(
                                    k =>
                                    string.Equals(k.RawName, KotaMadyaOrKabupatenName,
                                                  StringComparison.CurrentCultureIgnoreCase));
                        }
                        else
                        {
                            throw new Exception("The current provinse should never be null");
                        }
                    }
                    else if (string.IsNullOrWhiteSpace(ProvinceName) &&
                             String.IsNullOrEmpty(KotaMadyaOrKabupatenName) &&
                             !string.IsNullOrEmpty(KecamatanName))
                    {
                        if (currentKota != null)
                        {
                            if (
                                !currentKota.KecamatanList.Any(
                                    k =>
                                    string.Equals(k.RawName, KecamatanName, StringComparison.CurrentCultureIgnoreCase)))
                            {
                                var kecamatan = new Kecamatan(KecamatanName, currentKota);
                                currentKota.KecamatanList.Add(kecamatan);
                            }
                        }
                    }
                }
                row++;

                //6. Free resources (IExcelDataReader is IDisposable)
                excelReader.Close();
            }
        }
 public JNERate(Kota kota)
 {
     this.Kota = kota;
 }
        public void Parse(string filePath, IList <Province> ProvinceList)
        {
            FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
            //...
            //1. Reading from a binary Excel file ('97-2003 format; *.xls)
            IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            //...
            //3. DataSet - The result of each spreadsheet will be created in the result.Tables
            DataSet result = excelReader.AsDataSet();

            //5. Data Reader methods
            Province currentProvince = null;
            Kota     currentKota     = null;
            var      row             = 0;
            var      l = new List <string>();

            while (excelReader.Read())
            {
                var ProvinceName             = excelReader.GetString(PropinsiColumnIndex);
                var KotaMadyaOrKabupatenName = excelReader.GetString(KotamadyaOrKabupatenColumnIndex);
                var KecamatanName            = excelReader.GetString(KecamatanColumnIndex);
                if (row >= 9)
                {
                    int j = 0;
                    if (!string.IsNullOrWhiteSpace(ProvinceName) && String.IsNullOrEmpty(KotaMadyaOrKabupatenName) &&
                        string.IsNullOrEmpty(KecamatanName))
                    {
                        if (
                            !ProvinceList.Any(
                                p => String.Equals(p.Name, ProvinceName, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            ProvinceList.Add(new Province(ProvinceName));
                        }
                        var Propinsi = ProvinceList.First(
                            p => String.Equals(p.Name, ProvinceName, StringComparison.InvariantCultureIgnoreCase));
                        currentProvince = Propinsi;
                    }
                    else if (string.IsNullOrWhiteSpace(ProvinceName) && !String.IsNullOrEmpty(KotaMadyaOrKabupatenName) &&
                             string.IsNullOrEmpty(KecamatanName))
                    {
                        if (currentProvince != null)
                        {
                            if (
                                !currentProvince.KotaList.Any(
                                    k =>
                                    string.Equals(k.RawName, KotaMadyaOrKabupatenName,
                                                  StringComparison.CurrentCultureIgnoreCase)))
                            {
                                var kota = new Kota(KotaMadyaOrKabupatenName, string.Empty, currentProvince);
                                currentProvince.KotaList.Add(kota);
                            }
                            currentKota =
                                currentProvince.KotaList.First(
                                    k =>
                                    string.Equals(k.RawName, KotaMadyaOrKabupatenName,
                                                  StringComparison.CurrentCultureIgnoreCase));
                        }
                        else
                        {
                            throw new Exception("The current provinse should never be null");
                        }
                    }
                    else if (string.IsNullOrWhiteSpace(ProvinceName) &&
                             String.IsNullOrEmpty(KotaMadyaOrKabupatenName) &&
                             !string.IsNullOrEmpty(KecamatanName))
                    {
                        if (currentKota != null)
                        {
                            if (
                                !currentKota.KecamatanList.Any(
                                    k =>
                                    string.Equals(k.RawName, KecamatanName, StringComparison.CurrentCultureIgnoreCase)))
                            {
                                var kecamatan = new Kecamatan(KecamatanName, currentKota);
                                currentKota.KecamatanList.Add(kecamatan);
                            }
                        }
                    }
                }
                row++;

                //6. Free resources (IExcelDataReader is IDisposable)
                excelReader.Close();
            }
        }
Beispiel #8
0
 public JNERate(Kota kota)
 {
     this.Kota = kota;
 }