private void workerTM_DoWork(object sender, DoWorkEventArgs e)
        {
            foreach (DataRow row in uploadTable.Rows)
            {
                string chaseno = row.ItemArray[0].ToString();

                if (chaseno.StartsWith("CM"))
                {
                    string instockdate = ImportXls2007Util.ParseDateTime(row.ItemArray[3].ToString()).ToString("yyyy/MM/dd");

                    string query = string.Format("update tb_betamould set tm_instockdate = '{0}', tm_st_code = 'S' where tm_chaseno = '{1}'", instockdate, chaseno);
                    DataService.GetInstance().ExecuteNonQuery(query);
                }
                else
                {
                    string checkdate      = row.ItemArray[1].ToString();
                    string instockremarks = row.ItemArray[2].ToString();
                    string instockdate    = row.ItemArray[3].ToString();

                    string datetime = DateTime.Today.ToString("yyyy/MM/dd");

                    checkdate = ImportXlsUtil.ParseDateTime(checkdate).ToString("yyyy/MM/dd");
                    if (checkdate == "0001/01/01")
                    {
                        checkdate = "";
                    }

                    instockdate = ImportXlsUtil.ParseDateTime(instockdate).ToString("yyyy/MM/dd");
                    if (instockdate == "0001/01/01")
                    {
                        instockdate = "";
                    }

                    string query = string.Format("update tb_betamould set tm_instockdate = '{0}', tm_st_code = 'S', tm_checkdate = '{1}', tm_instockremarks = '{2}', tm_moulditemviewer = 'Yes' where tm_chaseno = '{3}'", instockdate, checkdate, instockremarks, chaseno);

                    DataService.GetInstance().ExecuteNonQuery(query);
                }
            }
        }
        private void btnUploadTM_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog()
            {
                Filter = "Excel Files |*.xls;*.xlsx"
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                filename = ofd.FileName;

                uploadTable = new DataTable();

                uploadTable = ofd.FileName.EndsWith(".xls") ? ImportXlsUtil.TranslateToTable(ofd.FileName) : ImportXls2007Util.TranslateToTable(ofd.FileName);

                DataTable tmptable = new DataTable();

                tmptable.Columns.Add("Chase No.");
                tmptable.Columns.Add("Check Date");
                tmptable.Columns.Add("In Stock Remarks");
                tmptable.Columns.Add("In Stock Date");

                foreach (DataRow row in uploadTable.Rows)
                {
                    string chaseno = row.ItemArray[0].ToString();

                    if (chaseno.StartsWith("CM"))
                    {
                        string instockdate = ImportXls2007Util.ParseDateTime(row.ItemArray[3].ToString()).ToString("yyyy/MM/dd");

                        tmptable.Rows.Add(new object[] { chaseno, "", "", instockdate });
                    }
                    else
                    {
                        string checkdate = ImportXlsUtil.ParseDateTime(row.ItemArray[1].ToString()).ToString("yyyy/MM/dd");
                        if (checkdate == "0001/01/01")
                        {
                            checkdate = "";
                        }

                        string instockremarks = row.ItemArray[2].ToString();

                        string instockdate = ImportXlsUtil.ParseDateTime(row.ItemArray[3].ToString()).ToString("yyyy/MM/dd");

                        tmptable.Rows.Add(new object[] { chaseno, checkdate, instockremarks, instockdate });
                    }
                }

                frmUploadConfirm form = new frmUploadConfirm(tmptable);
                form.ShowDialog();

                if (form.DialogResult == DialogResult.OK)
                {
                    if (!workerTM.IsBusy)
                    {
                        this.Cursor       = Cursors.WaitCursor;
                        dgvPreview.Cursor = Cursors.WaitCursor;
                        dgvResult.Cursor  = Cursors.WaitCursor;
                        workerTM.RunWorkerAsync();
                    }
                    else
                    {
                        MessageBox.Show("Using by other process");
                    }
                }
            }
        }