コード例 #1
0
        private void btnChooseFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "Excel Files|*.xls;*.xlsx";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var dtProductFile = Common.GetDataTableFromExcelUsingOLEDB(openFileDialog1.FileName, "YES");
                    if (dtProductFile.Rows.Count == 0)
                    {
                        lbCount.Text = "Count: 0";
                        MessageBox.Show("File không có dữ liệu!");
                    }
                    else
                    {
                        int checkedSql   = 0;
                        int uncheckedSql = 0;
                        for (int i = 0; i < dtProductFile.Rows.Count; i++)
                        {
                            var drProduct = dBProduct.Product.NewRow();
                            drProduct["Name"]      = dtProductFile.Rows[i][0];
                            drProduct["DetailUrl"] = dtProductFile.Rows[i][1];
                            var productId   = Common.GetIDProduct(dtProductFile.Rows[i][1].ToString());
                            var productTemp = new DBProduct.ProductDataTable();
                            productTableAdapter.FillBy_Id(productTemp, productId);
                            if (productTemp.Rows.Count == 0)
                            {
                                uncheckedSql++;
                                continue;
                            }

                            else
                            {
                                drProduct["ID"] = productId;
                                checkedSql++;
                            }
                            dBProduct.Product.Rows.Add(drProduct);
                        }
                        lbCheckedSql.Text   = checkedSql.ToString();
                        lbUnCheckedSql.Text = uncheckedSql.ToString();
                        productGridControl.RefreshDataSource();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi: " + ex.Message);
                }
            }
        }
コード例 #2
0
        private string GetImagePath(long id, ProductTableAdapter productAdapter)
        {
            var imagePath    = "";
            var productTable = new DBProduct.ProductDataTable();

            try
            {
                productAdapter.FillById(productTable, id);
                if (productTable.Rows.Count > 0)
                {
                    imagePath = productTable.Rows[0]["ImagePath"].ToString();
                }
            }
            catch (Exception exception)
            {
                Log.Error(id + exception.ToString());
            }
            return(imagePath);
        }