Пример #1
0
        public static void importTrade(Trade trade)
        {
            DataSet1.TradeDataTable tradeRows = GetTradeRows();
            DataRow[] dataRows = tradeRows.Select();
            int       number   = 0;

            if (dataRows.Length > 0)
            {
                int size = dataRows.Length;
                for (int i = 0; i < size; i++)
                {
                    if ((int)dataRows[i][15] > number)
                    {
                        number = (int)dataRows[i][15];
                    }
                }
                number++;
            }
            DataRow dataRow = tradeRows.NewRow();

            dataRow[0]  = trade.category;
            dataRow[1]  = trade.transaction;
            dataRow[2]  = trade.deadline;
            dataRow[3]  = trade.orderer;
            dataRow[4]  = trade.demander;
            dataRow[5]  = trade.contents;
            dataRow[6]  = trade.product;
            dataRow[7]  = trade.OS;
            dataRow[8]  = trade.quantity;
            dataRow[9]  = trade.price;
            dataRow[10] = trade.manager;
            dataRow[11] = trade.inspection;
            dataRow[12] = trade.bill;
            dataRow[13] = trade.modify;
            dataRow[14] = trade.registrar;
            dataRow[15] = number;
            tradeRows.Rows.Add(dataRow);
            tradeRows.WriteXml(filepath + "trade_data.xml");

            DirectoryInfo di = new DirectoryInfo(filepath + '/' + dataRow[15].ToString());

            if (!di.Exists)
            {
                di.Create();
            }
            else
            {
                di.Delete(true);
                di.Create();
            }

            return;
        }
Пример #2
0
        private void BtnUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Excel Files (*.xls)|*.xls";
            DialogResult dialogResult = openFileDialog.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                string filepath = openFileDialog.FileName;

                FileStream              stream      = File.Open(filepath, FileMode.Open, FileAccess.Read);
                IExcelDataReader        excelReader = ExcelReaderFactory.CreateReader(stream);
                DataSet1.TradeDataTable tradeRows   = SendClass.GetTradeRows();
                DataSet result = excelReader.AsDataSet();
                for (int i = 1; i < result.Tables[0].Rows.Count; i++)
                {
                    DataRow dataRow = tradeRows.NewRow();
                    dataRow[0] = result.Tables[0].Rows[i][1];
                    string transaction = result.Tables[0].Rows[i][2].ToString();

                    dataRow[1] = new DateTime(int.Parse(transaction.Substring(0, 4)),
                                              int.Parse(transaction.Substring(5, 2)), int.Parse(transaction.Substring(8, 2)));
                    string deadline = result.Tables[0].Rows[i][3].ToString();
                    dataRow[2] = new DateTime(int.Parse(deadline.Substring(0, 4)),
                                              int.Parse(deadline.Substring(5, 2)), int.Parse(deadline.Substring(8, 2)));
                    dataRow[3]  = result.Tables[0].Rows[i][5];
                    dataRow[4]  = result.Tables[0].Rows[i][6];
                    dataRow[5]  = result.Tables[0].Rows[i][7];
                    dataRow[6]  = result.Tables[0].Rows[i][8];
                    dataRow[7]  = result.Tables[0].Rows[i][9];
                    dataRow[8]  = int.Parse(result.Tables[0].Rows[i][10].ToString());
                    dataRow[9]  = int.Parse(result.Tables[0].Rows[i][11].ToString());
                    dataRow[10] = result.Tables[0].Rows[i][12];
                    string inspection = result.Tables[0].Rows[i][13].ToString();
                    if (inspection.Length > 0)
                    {
                        dataRow[11] = new DateTime(int.Parse(inspection.Substring(0, 4)),
                                                   int.Parse(inspection.Substring(5, 2)), int.Parse(inspection.Substring(8, 2)));
                    }
                    else
                    {
                        dataRow[11] = new DateTime();
                    }
                    string bill = result.Tables[0].Rows[i][14].ToString();
                    if (bill.Length > 0)
                    {
                        dataRow[12] = new DateTime(int.Parse(bill.Substring(0, 4)),
                                                   int.Parse(bill.Substring(5, 2)), int.Parse(bill.Substring(8, 2)));
                    }
                    else
                    {
                        dataRow[12] = new DateTime();
                    }
                    dataRow[13] = new DateTime();
                    dataRow[14] = result.Tables[0].Rows[i][15];
                    dataRow[15] = int.Parse(result.Tables[0].Rows[i][0].ToString());
                    tradeRows.Rows.Add(dataRow);
                }
                tradeRows.WriteXml(SendClass.filepath + "trade_data.xml");
            }
        }