private void newListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            FileStream       stream = File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read);
            IExcelDataReader excelReader;

            var ext = Path.GetExtension(openFileDialog.FileName);

            if (ext == ".xls")
            {
                excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            }
            else
            {
                excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            }

            if (excelReader == null) // || !excelReader.IsValid)
            {
                MessageBox.Show("Selected file is not valid Excel file");
                return;
            }

            //CultureInfo culture = new CultureInfo("en-US");
            var culture = CultureInfo.CreateSpecificCulture("en-US");

            this.opsDataSet.ZMSL.Clear();
            int      i = 0;
            DateTime ld;

            excelReader.IsFirstRowAsColumnNames = true;     // Nuget 3.4e Update'den sonra bozuldu, eskisine 3.0.develop00019 a geri aldim
            excelReader.Read();
            while (excelReader.Read())
            {
                i++;
                OpsDataSet.ZMSLRow row = opsDataSet.ZMSL.NewZMSLRow();
                //row.ID = i++;
                // var bbb = excelReader.GetOrdinal("Template"); Calismiyor
                row.TEMPLATE = excelReader.GetString(0);

                if (DateTime.TryParse(excelReader.GetString(1), out ld))
                {
                    row.LOADINGDATE = ld;
                }

/*
 *              try
 *              {
 *                  //MessageBox.Show(excelReader.GetString(1));
 *                  //row.LOADINGDATE = Convert.ToDateTime(excelReader.GetString(1).Substring(0, 10));
 *                  ld = DateTime.Parse(excelReader.GetString(1));
 *                  row.LOADINGDATE = ld;
 *                  //MessageBox.Show(excelReader.GetString(1) + "  " + row.LOADINGDATE.ToString());
 *                  //row.LOADINGDATE = Convert.ToDateTime(excelReader.GetValue(1), culture); //excelReader.GetDateTime(1); //.ToString();  //Convert.ToDateTime(excelReader.GetString(1).Substring(0, 10));
 *              }
 *              catch (Exception ee)
 *              {
 *                  //MessageBox.Show(excelReader.GetString(1));
 *                  //ld = DateTime.Parse(excelReader.GetString(1), culture);
 *                  //row.LOADINGDATE = ld;
 *              }
 */
                row.STATUS   = excelReader.GetString(2);
                row.PROTOCOL = excelReader.GetString(3);
                row.SPONSOR  = excelReader.GetString(4);
                row.STUDY    = excelReader.GetString(5);
                row.SITE     = excelReader.GetString(6);

                row.WEEKAMB = excelReader.GetString(8);
                row.WEEKREF = excelReader.GetString(9);
                row.WEEKFRZ = excelReader.GetString(10);
                //
                row.WEEKENDAMB = excelReader.GetString(12);
                row.WEEKENDREF = excelReader.GetString(13);
                row.WEEKENDFRZ = excelReader.GetString(14);

                row.CONSIGNEECOMPANY     = excelReader.GetString(19);
                row.CONSIGNEECITY        = excelReader.GetString(23);
                row.CONSIGNEECOUNTRYCODE = excelReader.GetString(26);
                row.PICKUPNAME           = excelReader.GetString(50);
                row.PICKUPCOMPANY        = excelReader.GetString(51);
                row.PICKUPDEPARTMENT     = excelReader.GetString(52);
                row.PICKUPCITY           = excelReader.GetString(55);
                row.PICKUPPHONE          = excelReader.GetString(59);

                opsDataSet.ZMSL.AddZMSLRow(row);
            }
            excelReader.Close();
        }
Exemple #2
0
        private void newListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                FileStream stream = File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read);

                var ext = Path.GetExtension(openFileDialog.FileName);
                if (ext == ".xls")
                {
                    excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
                }
                else if (ext == ".xlsx")
                {
                    excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                }

                if (excelReader == null) // || !excelReader.IsValid)
                {
                    MessageBox.Show("Selected file is not valid Excel file");
                    return;
                }

                /*
                 * excelReader.IsFirstRowAsColumnNames = true;
                 * result = excelReader.AsDataSet();
                 * mslGridControl.DataSource = result.Tables[0];
                 * mslGridView.OptionsView.ColumnAutoWidth = false;
                 */

                CultureInfo culture = new CultureInfo("en-US");
                this.opsDataSet.ZMSL.Clear();
                int i = 0;
                excelReader.Read();
                while (excelReader.Read())
                {
                    i++;
                    OpsDataSet.ZMSLRow row = opsDataSet.ZMSL.NewZMSLRow();
                    //row.ID = i++;
                    // var bbb = excelReader.GetOrdinal("Template"); Calismiyor
                    row.TEMPLATE = excelReader.GetString(0);
                    //var aaa = excelReader.GetString(1);
                    //var ccc = Convert.ToDateTime(excelReader.GetValue(1), culture);
                    //var bbb = excelReader.GetDateTime(1);
                    row.LOADINGDATE = Convert.ToDateTime(excelReader.GetValue(1), culture); //excelReader.GetDateTime(1); //.ToString();  //Convert.ToDateTime(excelReader.GetString(1).Substring(0, 10));
                    //if (excelReader.GetValue(1).GetType().Name != "DateTime")
                    //    MessageBox.Show(excelReader.GetValue(1).GetType().Name);
                    //row.Status = excelReader.GetString(2);
                    row.PROTOCOL         = excelReader.GetString(3);
                    row.SPONSOR          = excelReader.GetString(4);
                    row.STUDY            = excelReader.GetString(5);
                    row.SITE             = excelReader.GetString(6);
                    row.CONSIGNEENAME    = excelReader.GetString(18);
                    row.PICKUPNAME       = excelReader.GetString(50);
                    row.PICKUPCOMPANY    = excelReader.GetString(51);
                    row.PICKUPDEPARTMENT = excelReader.GetString(52);
                    row.PICKUPCITY       = excelReader.GetString(55);
                    row.PICKUPPHONE      = excelReader.GetString(59);

                    opsDataSet.ZMSL.AddZMSLRow(row);
                }
                excelReader.Close();
            }
        }