Exemple #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            string         filePath = string.Empty;
            string         fileExt  = string.Empty;
            OpenFileDialog file     = new OpenFileDialog();                //open dialog to choose file

            if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK) //if there is a file choosen by the user
            {
                filePath = file.FileName;                                  //get the path of the file
                fileExt  = Path.GetExtension(filePath);                    //get the file extension
                if (fileExt.CompareTo(".xls") == 0 || fileExt.CompareTo(".xlsx") == 0)
                {
                    //try
                    //{
                    DataTable dtExcel = new DataTable();
                    if (string.IsNullOrEmpty(categoryTxt.Text))
                    {
                        MessageBox.Show("Please select the category ");
                        categoryTxt.BackColor = Color.Red;
                        return;
                    }
                    if (MessageBox.Show("YES or No?", "Confirm the year  " + Convert.ToDateTime(dateTxt.Text).Year.ToString(), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        if (categoryTxt.Text.Contains("COGS"))
                        {
                            if (string.IsNullOrEmpty(subcategory.Text))
                            {
                                subcategory.BackColor = Color.Pink;
                                MessageBox.Show("Please select the cost of goods category");
                                return;
                            }
                        }
                        if (categoryTxt.Text.Contains("Purchases"))
                        {
                            if (string.IsNullOrEmpty(subcategory.Text))
                            {
                                subcategory.BackColor = Color.Pink;
                                MessageBox.Show("Please select the Purchase category");
                                return;
                            }
                        }
                        if (categoryTxt.Text.Contains("Expenses"))
                        {
                            if (string.IsNullOrEmpty(subcategory.Text))
                            {
                                subcategory.BackColor = Color.Pink;
                                MessageBox.Show("Please select the category !");
                                return;
                            }
                        }

                        LoadingWindow.ShowSplashScreen();
                        ReadExcel(filePath, fileExt); //read excel file
                        LoadingWindow.CloseForm();
                    }
                    //  dataGridView1.Visible = true;
                    // dataGridView1.DataSource = dtExcel;
                    //}
                    //catch (Exception ex)
                    //{
                    //    MessageBox.Show(ex.Message.ToString());
                    //}
                }
                else
                {
                    MessageBox.Show("Please choose .xls or .xlsx file only.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); //custom messageBox to show error
                }
            }
        }
Exemple #2
0
 static private void ShowForm()
 {
     splashForm = new LoadingWindow();
     Application.Run(splashForm);
 }