コード例 #1
0
ファイル: WorkOrder.cs プロジェクト: yeef93/ComparesWOLL
        private void dataGridViewWoList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int i;

            i = dataGridViewWoList.SelectedCells[0].RowIndex;
            string woPTSNslctd = dataGridViewWoList.Rows[i].Cells[1].Value.ToString();

            if (e.ColumnIndex == 7)
            {
                DetailWO dwo     = new DetailWO();
                string   cust    = dataGridViewWoList.Rows[e.RowIndex].Cells[0].Value.ToString();
                string   woPtsn  = dataGridViewWoList.Rows[e.RowIndex].Cells[1].Value.ToString();
                string   modelNo = dataGridViewWoList.Rows[e.RowIndex].Cells[2].Value.ToString();
                string   model   = dataGridViewWoList.Rows[e.RowIndex].Cells[3].Value.ToString();
                string   woNo    = dataGridViewWoList.Rows[e.RowIndex].Cells[4].Value.ToString();
                //string processName = dataGridViewWoList.Rows[e.RowIndex].Cells[4].Value.ToString();
                string woQty   = dataGridViewWoList.Rows[e.RowIndex].Cells[5].Value.ToString();
                string woUsage = dataGridViewWoList.Rows[e.RowIndex].Cells[6].Value.ToString();

                dwo.tbCustomer.Text = cust;
                dwo.tbwoPTSN.Text   = woPtsn;
                dwo.tbwoNo.Text     = woNo;
                dwo.tbmodelNo.Text  = modelNo;
                dwo.tbmodel.Text    = model;
                dwo.totalUsage.Text = woQty;
                dwo.woQty.Text      = woUsage;

                dwo.Show();
                this.Hide();
                //MessageBox.Show((e.RowIndex + 1) + "  Row  " + (e.ColumnIndex + 1) + "  Column button clicked ");
            }

            if (e.ColumnIndex == 8)
            {
                ImportLL il     = new ImportLL();
                string   woPtsn = dataGridViewWoList.Rows[e.RowIndex].Cells[1].Value.ToString();
                string   cust   = dataGridViewWoList.Rows[e.RowIndex].Cells[0].Value.ToString();

                il.Show();
                il.tbWoPTSN.Text = woPtsn;
                il.tbCust.Text   = cust;

                connection.Open();

                string queryProcessDropDown = "SELECT process_Name FROM tbl_customer WHERE custname = '" + cust + "'";

                try
                {
                    using (MySqlDataAdapter adpt = new MySqlDataAdapter(queryProcessDropDown, connection))
                    {
                        DataTable dset = new DataTable();
                        adpt.Fill(dset);

                        if (dset.Rows.Count > 0)
                        {
                            string process      = dset.Rows[0][0].ToString().Replace(" ", String.Empty);;
                            int    totalProcess = process.Split(',').Length;
                            var    processName  = process.Split(',');

                            for (int j = 0; j < totalProcess; j++)
                            {
                                il.cmbProcess.Items.Add(processName[j]);
                                il.cmbProcess.ValueMember = processName[j].ToString();
                            }
                        }
                        else
                        {
                        }
                    }

                    connection.Close();
                }
                catch (Exception ex)
                {
                    // tampilkan pesan error
                    MessageBox.Show(ex.Message);
                }

                this.Hide();
                //MessageBox.Show((e.RowIndex + 1) + "  Row  " + (e.ColumnIndex + 1) + "  Column button clicked "+model+"");
            }

            if (e.ColumnIndex == 9)
            {
                string woPtsn = dataGridViewWoList.Rows[e.RowIndex].Cells[1].Value.ToString();

                Compare cowl = new Compare();
                cowl.cmbWOPtsn.Text = woPtsn;
                cowl.Show();
                this.Hide();
            }

            if (e.ColumnIndex == 10)
            {
                string            message = "Do you want to delete this Work Order and Loading List record for WO PTSN " + woPTSNslctd + " ?";
                string            title   = "Delete Work Order";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result  = MessageBox.Show(message, title, buttons);
                if (result == DialogResult.Yes)
                {
                    var cmd = new MySqlCommand("", connection);

                    string querydeleteWO       = "DELETE FROM tbl_wo WHERE wo_PTSN = '" + woPTSNslctd + "'";
                    string querydeleteWODetail = "DELETE FROM tbl_wodetail WHERE  wo_PTSN = '" + woPTSNslctd + "'";
                    string querydeleteModel    = "DELETE FROM tbl_model WHERE  wo_PTSN = '" + woPTSNslctd + "'";

                    string querydeleteLL       = "DELETE FROM tbl_ll WHERE wo_PTSN = '" + woPTSNslctd + "'";
                    string querydeleteLLDetail = "DELETE FROM tbl_lldetail WHERE wo_PTSN = '" + woPTSNslctd + "'";
                    string querydeletePartCode = "DELETE FROM tbl_partcodedetail WHERE wo_PTSN = '" + woPTSNslctd + "'";
                    string querydeleteReel     = "DELETE FROM tbl_reel WHERE wo_PTSN= '" + woPTSNslctd + "'";
                    string querydeleteResult   = "DELETE FROM tbl_resultcompare WHERE wo_PTSN = '" + woPTSNslctd + "'";

                    connection.Open();

                    string[] allQuery = { querydeleteWO, querydeleteWODetail, querydeleteModel, querydeleteLL, querydeleteLLDetail, querydeletePartCode, querydeleteReel, querydeleteResult };
                    for (int j = 0; j < allQuery.Length; j++)
                    {
                        cmd.CommandText = allQuery[j];
                        //Masukkan perintah/query yang akan dijalankan ke dalam CommandText
                        cmd.ExecuteNonQuery();
                        //Jalankan perintah / query dalam CommandText pada database
                    }

                    connection.Close();
                    WorkOrder wo = new WorkOrder();
                    wo.Show();
                    this.Hide();
                    MessageBox.Show("Record Deleted successfully", "Work Order Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                }
            }
        }
コード例 #2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            StartProgress("Loading...");

            homeButton.Enabled = false;
            backButton.Enabled = false;

            System.Threading.Thread.Sleep(2000);

            string woPTSNN  = tbwoPTSN.Text;
            string woNoo    = tbwoNo.Text;
            string modelNoo = tbmodelNo.Text;
            string modell   = tbmodel.Text;
            string woqtyy   = tbtotalUsage.Text;
            string wousagee = tbwoQty.Text;
            string customer = cmbCustomer.Text;

            saveButton.Enabled = false;


            if (woPTSNN == "" | woNoo == "" | modelNoo == "" | modell == "" | woqtyy == "")
            {
                CloseProgress();
                saveButton.Enabled = true;
                MessageBox.Show("Unable to import Work Order without fill data properly", "Work Order", MessageBoxButtons.OK, MessageBoxIcon.Error);
                homeButton.Enabled = true;
                backButton.Enabled = true;
            }

            else
            {
                try
                {
                    var cmd = new MySqlCommand("", connection);

                    connection.Open();
                    //Buka koneksi

                    string cekwoPTSN   = "SELECT wo_PTSN FROM tbl_wo  WHERE wo_PTSN = '" + woPTSNN + "'";
                    string query       = "INSERT INTO tbl_wo VALUES('', '" + woPTSNN + "','" + woNoo + "','" + modelNoo + "','" + modell + "', '" + woqtyy + "', '" + wousagee + "', '" + customer + "')";
                    string querymodel  = "INSERT INTO tbl_model ( wo_PTSN, process_Name ) SELECT wo_PTSN, process_Name FROM tbl_wodetail GROUP BY process_Name, wo_PTSN";
                    string trncteModel = "TRUNCATE tbl_model";

                    using (MySqlDataAdapter dscmd = new MySqlDataAdapter(cekwoPTSN, connection))
                    {
                        DataSet ds = new DataSet();
                        dscmd.Fill(ds);

                        if (ds.Tables[0].Rows.Count >= 1)
                        {
                            CloseProgress();
                            MessageBox.Show("Work Order PTSN " + woPTSNN + "  already uploaded", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); //custom messageBox to show error
                            tbfilepathWO.Text         = "";
                            tbwoPTSN.Text             = "";
                            tbwoNo.Text               = "";
                            tbmodelNo.Text            = "";
                            tbmodel.Text              = "";
                            tbtotalPart.Text          = "";
                            tbtotalUsage.Text         = "";
                            tbwoQty.Text              = "";
                            dataGridViewWO.DataSource = null;
                            dataGridViewWO.Refresh();

                            homeButton.Enabled = true;
                            backButton.Enabled = true;

                            connection.Close();
                        }

                        else
                        {
                            cmd.CommandText = trncteModel;
                            cmd.ExecuteNonQuery();

                            cmd.CommandText = query;
                            cmd.ExecuteNonQuery();

                            for (int i = 0; i < dataGridViewWO.Rows.Count; i++)
                            {
                                string StrQuery = "INSERT INTO tbl_wodetail VALUES ('"
                                                  + dataGridViewWO.Rows[i].Cells[8].Value.ToString() + "', '"
                                                  + dataGridViewWO.Rows[i].Cells[1].Value.ToString() + "', '"
                                                  + dataGridViewWO.Rows[i].Cells[7].Value.ToString() + "', '"
                                                  + dataGridViewWO.Rows[i].Cells[3].Value.ToString() + "', '"
                                                  + dataGridViewWO.Rows[i].Cells[6].Value.ToString() + "', '"
                                                  + dataGridViewWO.Rows[i].Cells[4].Value.ToString() + "');";
                                cmd.CommandText = StrQuery;
                                cmd.ExecuteNonQuery();
                            }

                            cmd.CommandText = querymodel;
                            cmd.ExecuteNonQuery();

                            connection.Close();
                            //Tutup koneksi
                            CloseProgress();
                            MessageBox.Show("Work Order Successfully saved", "Work Order", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            saveButton.Enabled = true;

                            this.Close();
                            WorkOrder wo = new WorkOrder();
                            wo.Show();
                        }
                    }
                }
                catch (Exception ex)
                {
                    CloseProgress();
                    MessageBox.Show(ex.Message.ToString());
                    saveButton.Enabled = true;
                }
            }
        }