Exemplo n.º 1
0
        private void btnOpenExcel_Click(object sender, EventArgs e)
        {
            try
            {
                txtBlockNo.EditValue    = objMasterService.GetNew_Sochungtu("ware_dm_hanghoa_ban_import", "block_no", "");
                frmImportFromExcel      = new  GoobizFrame.Windows.Tools.FrmImportFromExcel();
                frmImportFromExcel.Text = "Nhập hàng hóa từ file Excel";
                frmImportFromExcel.ShowDialog();
                if (frmImportFromExcel.DsImportData != null && frmImportFromExcel.DsImportData.Tables.Count > 0)
                {
                    dsMaps = new DataSet();
                    dsMaps.Tables.Add();
                    dsMaps.Tables[0].Columns.Add("Excel_Col");
                    dsMaps.Tables[0].Columns.Add("FieldName");
                    foreach (DataColumn col in frmImportFromExcel.DsImportData.Tables[0].Columns)
                    {
                        DataRow ndr = dsMaps.Tables[0].NewRow();
                        ndr["Excel_Col"] = col.ColumnName;
                        dsMaps.Tables[0].Rows.Add(ndr);
                    }
                    dsMaps.AcceptChanges();
                    dgColumnsMap.DataSource = dsMaps;
                    dgColumnsMap.DataMember = dsMaps.Tables[0].TableName;
                    //show selected data
                    gridView3.Columns.Clear();
                    int visibleIndex = 0;
                    foreach (DataColumn col in frmImportFromExcel.DsImportData.Tables[0].Columns)
                    {
                        try
                        {
                            DevExpress.XtraGrid.Columns.GridColumn GridColumn = new DevExpress.XtraGrid.Columns.GridColumn();
                            GridColumn.FieldName    = col.ColumnName;
                            GridColumn.Caption      = col.ColumnName;
                            GridColumn.VisibleIndex = visibleIndex++;
                            GridColumn.Visible      = true;

                            gridView3.Columns.Add(GridColumn);
                        }
                        catch (Exception ex) { continue; }
                    }

                    dgDataImport.DataSource = frmImportFromExcel.DsImportData;
                    dgDataImport.DataMember = frmImportFromExcel.DsImportData.Tables[0].TableName;
                    gridView3.BestFitColumns();
                    showTabPages(tab_ChonCot);
                }
            }
            catch (Exception ex)
            {
                GoobizFrame.Windows.Forms.MessageDialog.Show(ex.Message, ex.ToString(), "");
            }
        }
        private void btnOpenExcel_Click(object sender, EventArgs e)
        {
            FrmImportFromExcel = new GoobizFrame.Windows.Tools.FrmImportFromExcel();
            FrmImportFromExcel.ShowDialog();
            if (FrmImportFromExcel.DsImportData != null && FrmImportFromExcel.DsImportData.Tables.Count > 0)
            {
                dsMaps = new DataSet();
                dsMaps.Tables.Add();
                dsMaps.Tables[0].Columns.Add("Excel_Col");
                dsMaps.Tables[0].Columns.Add("FieldName");
                foreach (DataColumn col in FrmImportFromExcel.DsImportData.Tables[0].Columns)
                {
                    DataRow ndr = dsMaps.Tables[0].NewRow();
                    ndr["Excel_Col"] = col.ColumnName;
                    dsMaps.Tables[0].Rows.Add(ndr);
                }
                dsMaps.AcceptChanges();

                dgColumnsMap.DataSource = dsMaps;
                dgColumnsMap.DataMember = dsMaps.Tables[0].TableName;

                //show selected data
                gridView3.Columns.Clear();
                int visibleIndex = 0;
                foreach (DataColumn col in FrmImportFromExcel.DsImportData.Tables[0].Columns)
                {
                    try
                    {
                        DevExpress.XtraGrid.Columns.GridColumn GridColumn = new DevExpress.XtraGrid.Columns.GridColumn();
                        GridColumn.FieldName    = col.ColumnName;
                        GridColumn.Caption      = col.ColumnName;
                        GridColumn.VisibleIndex = visibleIndex++;
                        GridColumn.Visible      = true;

                        gridView3.Columns.Add(GridColumn);
                    }
                    catch (Exception ex) { continue; }
                }

                dgDataImport.DataSource = FrmImportFromExcel.DsImportData;
                dgDataImport.DataMember = FrmImportFromExcel.DsImportData.Tables[0].TableName;
                gridView3.BestFitColumns();
            }
        }