예제 #1
0
        public Winner()
        {
            InitializeComponent();

            if (File.Exists("Winner.csv"))
            {
                mTable = Methods.ConvertCSVtoDataTable2("Winner.csv");
            }
            else
            {
                mTable.Columns.Add("ID");
                mTable.Columns.Add("First Name");
                mTable.Columns.Add("Last Name");
                mTable.Columns.Add("Prize");
                mTable.Columns.Add("Date");
            }
            dataGridView1.DataSource = mTable;
            dataGridView1.Columns["Date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
        }
예제 #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            idList.Add(lID1);
            idList.Add(lID2);
            idList.Add(lID3);
            idList.Add(lID4);
            idList.Add(lID5);
            idList.Add(lID6);
            idList.Add(lID7);
            idList.Add(lID8);
            idList.Add(lID9);
            idList.Add(lID10);

            LNList.Add(lLN1);
            LNList.Add(lLN2);
            LNList.Add(lLN3);
            LNList.Add(lLN4);
            LNList.Add(lLN5);
            LNList.Add(lLN6);
            LNList.Add(lLN7);
            LNList.Add(lLN8);
            LNList.Add(lLN9);
            LNList.Add(lLN10);

            FNList.Add(lFN1);
            FNList.Add(lFN2);
            FNList.Add(lFN3);
            FNList.Add(lFN4);
            FNList.Add(lFN5);
            FNList.Add(lFN6);
            FNList.Add(lFN7);
            FNList.Add(lFN8);
            FNList.Add(lFN9);
            FNList.Add(lFN10);

            cbQuantity.SelectedIndex = 0;
            //



            for (int i = 0; i < 10; i++)
            {
                idList[i].Visible = false;
                FNList[i].Visible = false;
                LNList[i].Visible = false;
            }
            cbPrize.DataSource = setting.listPrize;
            //
            ToolStripControlHost host = new ToolStripControlHost(drawButton);
            ToolStripControlHost box1 = new ToolStripControlHost(cbQuantity);
            ToolStripControlHost box2 = new ToolStripControlHost(cbPrize);

            toolStrip1.Items.Add(host);
            toolStrip1.Items.Add(box1);
            toolStrip1.Items.Add(box2);
            //load exel file
            if (File.Exists("Participant.csv"))
            {
                setting.Table = Methods.ConvertCSVtoDataTable1("Participant.csv");
            }
            else
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title  = "Choose data source";
                ofd.Filter = "Excel File (*.xlsx)|*.xlsx|07-2003 Excel File (*.xls)|*.xls|all file (*.*)|*.*";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    /*setting.Table.Clear();
                     *
                     * Excel.Application xlApp = new Excel.Application();
                     * Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(ofd.FileName);
                     * Excel._Worksheet xlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets[1];
                     * Excel.Range xlRange = xlWorksheet.UsedRange;
                     *
                     * int RowCount = xlRange.Rows.Count;
                     * int ColCount = xlRange.Columns.Count;
                     *
                     * string tempID = null;
                     * string tempFirstName = null;
                     * string tempLastName = null;
                     *
                     * for (int i = 1; i <= RowCount; i++)
                     * {
                     *  tempID = xlRange.Cells[i, 1].Value2.ToString();
                     *  tempFirstName = xlRange.Cells[i, 2].Value2.ToString();
                     *  tempLastName = xlRange.Cells[i, 3].Value2.ToString();
                     *  DataRow newrow = setting.Table.NewRow();
                     *  newrow[0] = tempID;
                     *  newrow[1] = tempFirstName;
                     *  newrow[2] = tempLastName;
                     *  setting.Table.Rows.Add(newrow);
                     * }
                     * //cleanup
                     * GC.Collect();
                     * GC.WaitForPendingFinalizers();
                     *
                     * //rule of thumb for releasing com objects:
                     * //  never use two dots, all COM objects must be referenced and released individually
                     * //  ex: [somthing].[something].[something] is bad
                     *
                     * //release com objects to fully kill excel process from running in the background
                     * Marshal.ReleaseComObject(xlRange);
                     * Marshal.ReleaseComObject(xlWorksheet);
                     *
                     * //close and release
                     * xlWorkbook.Close();
                     * Marshal.ReleaseComObject(xlWorkbook);
                     *
                     * //quit and release
                     * xlApp.Quit();
                     * Marshal.ReleaseComObject(xlApp);*/

                    File.WriteAllText("Participant.csv", Methods.ExcelToCSV(ofd.FileName, ';').ToString());
                    setting.Table = Methods.ConvertCSVtoDataTable1("Participant.csv");
                    MessageBox.Show("Loading Done");
                }
            }
            if (File.Exists("Winner.csv"))
            {
                winner.Table = Methods.ConvertCSVtoDataTable2("Winner.csv");
            }
        }