Пример #1
0
        private void ImportExcel()
        {
            if (ValidateColumnInput())
              {
            var command = new OleDbCommand(string.Format("SELECT * FROM [{0}]", excelSheet.Text), Connection);
            var reader = command.ExecuteReader();
            var errorMsg = string.Empty;

            while (reader != null && reader.Read())
            {
              try
              {
            var paper = new Paper
            {
              ItemNumber = numberRow.Properties.Value == null ? 0 : Convert.ToInt32(reader[numberRow.Properties.Value.ToString()]),
              Name = reader[nameRow.Properties.Value.ToString()].ToString(),
              Direction = directionRow.Properties.Value == null ? 0 : Convert.ToInt32(reader[directionRow.Properties.Value.ToString()]),
              Amount1 = quantity1.Properties.Value == null ? 0 : Convert.ToInt32(reader[quantity1.Properties.Value.ToString()]),
              Amount2 = quantity2.Properties.Value == null ? 0 : Convert.ToInt32(reader[quantity2.Properties.Value.ToString()]),
              Amount3 = quantity3.Properties.Value == null ? 0 : Convert.ToInt32(reader[quantity3.Properties.Value.ToString()]),
              Price1 = Convert.ToInt32(reader[price1.Properties.Value.ToString()]),
              Price2 = price2.Properties.Value == null ? 0 : Convert.ToInt32(reader[price2.Properties.Value.ToString()]),
              Price3 = price3.Properties.Value == null ? 0 : Convert.ToInt32(reader[price3.Properties.Value.ToString()]),
              Price4 = price4.Properties.Value == null ? 0 : Convert.ToInt32(reader[price4.Properties.Value.ToString()]),
              SizeH = widthRow.Properties.Value == null ? 0 : Convert.ToInt32(reader[widthRow.Properties.Value.ToString()]),
              SizeW = lenghtRow.Properties.Value == null ? 0 : Convert.ToInt32(reader[lenghtRow.Properties.Value.ToString()]),
              Vendor = vendorRow.Properties.Value == null ? null : reader[vendorRow.Properties.Value.ToString()].ToString(),
              Weight = weightRow.Properties.Value == null ? 0 : Convert.ToInt32(reader[weightRow.Properties.Value.ToString()])
            };
            paper.SaveObject();
              }
              catch (Exception exception)
              {
            errorMsg += exception + Environment.NewLine;
              }
            }
            if (!string.IsNullOrEmpty(errorMsg))
            {
              XtraMessageBox.Show(errorMsg, "Aufgetretene Fehler beim Import");
            }
            Close();
              }
        }