Exemplo n.º 1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                backButton.Enabled = false;
                StartProgress("Loading...");
                //lf.Show();

                string cust    = tbCust.Text;
                string woPTSN  = tbWoPTSN.Text;
                string modelLL = tbModel.Text;
                string machine = tbMachine.Text;
                string pwbType = tbPWBType.Text;
                string prog    = tbProg.Text;
                string rev     = tbRev.Text;
                string pcb     = tbPcbNo.Text;
                string stencil = tbStencil.Text;
                string remark  = tbRemark.Text;
                string process = cmbProcess.Text;

                saveButton.Enabled = false;

                if (woPTSN == "" | process == "" | modelLL == "" | machine == "" | pwbType == "" | prog == "" | pcb == "")
                {
                    CloseProgress();
                    MessageBox.Show("Unable to import Work Order without fill data properly", "Work Order", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    saveButton.Enabled = true;
                    backButton.Enabled = true;
                }

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

                        string cekmodel            = "SELECT wo_PTSN, process_Name FROM tbl_ll  WHERE wo_PTSN = '" + woPTSN + "'AND process_Name ='" + process + "'";
                        string cekPCB              = "SELECT * FROM tbl_lldetail WHERE partcode = '" + pcb + "' AND wo_PTSN = '" + woPTSN + "' AND reel = 'PCB'";
                        string queryLL             = "INSERT INTO tbl_ll VALUES('','" + cust + "','" + woPTSN + "','" + process + "','" + modelLL + "','" + machine + "','" + pwbType + "','" + prog + "','" + rev + "','" + pcb + "','" + llUsage + "','" + stencil + "','" + remark + "')";
                        string queryInputPCB       = "INSERT INTO tbl_lldetail VALUES ('" + woPTSN + "','" + process + "','PCB', '" + pcb + "', '1', '1');";
                        string queryAddPartCodePCB = "INSERT INTO tbl_partcodedetail VALUES ('" + woPTSN + "','" + process + "','PCB',  '" + pcb + "', '','PCB' ); ";

                        connection.Open();
                        //Buka koneksi

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

                            if (ds.Tables[0].Rows.Count >= 1)
                            {
                                lf.Hide();
                                MessageBox.Show("Loading List Data with WO PTSN  " + woPTSN + " and Process " + process + "  already uploaded", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); //custom messageBox to show error
                                backButton.Enabled = true;
                            }

                            else
                            {
                                MySqlCommand     cmddb = new MySqlCommand(cekPCB, connection);
                                MySqlDataAdapter da    = new MySqlDataAdapter(cmddb);
                                DataSet          ds1   = new DataSet();
                                da.Fill(ds1);
                                int l = ds1.Tables[0].Rows.Count;
                                if (l == 0)
                                {
                                    string[] allQuery = { queryLL, queryInputPCB, queryAddPartCodePCB };
                                    for (int i = 0; i < allQuery.Length; i++)
                                    {
                                        cmd.CommandText = allQuery[i];
                                        //Masukkan perintah/query yang akan dijalankan ke dalam CommandText
                                        cmd.ExecuteNonQuery();
                                        //Jalankan perintah / query dalam CommandText pada database
                                    }
                                }
                                else
                                {
                                    string[] allQuery = { queryLL, queryAddPartCodePCB };
                                    for (int i = 0; i < allQuery.Length; i++)
                                    {
                                        cmd.CommandText = allQuery[i];
                                        //Masukkan perintah/query yang akan dijalankan ke dalam CommandText
                                        cmd.ExecuteNonQuery();
                                        //Jalankan perintah / query dalam CommandText pada database
                                    }
                                }

                                for (int i = 0; i < dataGridViewLL.Rows.Count; i++)
                                {
                                    string prtCode = dataGridViewLL.Rows[i].Cells[1].Value.ToString();

                                    if (prtCode != "")
                                    {
                                        // query insert data part code
                                        string StrQuery = "INSERT INTO tbl_partcodedetail VALUES ('" + woPTSN + "','" + process + "','"
                                                          + dataGridViewLL.Rows[i].Cells[0].Value.ToString() + "','"
                                                          + dataGridViewLL.Rows[i].Cells[1].Value.ToString() + "', '"
                                                          + dataGridViewLL.Rows[i].Cells[2].Value.ToString() + "', '"
                                                          + dataGridViewLL.Rows[i].Cells[5].Value.ToString() + "');";

                                        cmd.CommandText = StrQuery;
                                        cmd.ExecuteNonQuery();
                                    }
                                }

                                String reelID = "";
                                String qty    = "";
                                String loc    = "";

                                int altNo = 1;

                                for (int j = 0; j < dataGridViewLL.Rows.Count; j++)
                                {
                                    if (dataGridViewLL.Rows[j].Cells[0].Value.ToString() != "")
                                    {
                                        reelID = dataGridViewLL.Rows[j].Cells[0].Value.ToString();
                                        qty    = dataGridViewLL.Rows[j].Cells[3].Value.ToString();
                                        altNo  = 1;
                                        string StrQueryReelDetail = "INSERT INTO tbl_reel VALUES ('','"
                                                                    + reelID + "', '" + woPTSN + "','" + process + "','" + dataGridViewLL.Rows[j].Cells[3].Value.ToString() + "', '"
                                                                    + dataGridViewLL.Rows[j].Cells[4].Value.ToString() + "', '"
                                                                    + dataGridViewLL.Rows[j].Cells[6].Value.ToString() + "');";

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

                                        string StrQueryLLDetail = "INSERT INTO tbl_lldetail VALUES ('" + woPTSN + "','" + process + "','"
                                                                  + reelID + "', '"
                                                                  + dataGridViewLL.Rows[j].Cells[1].Value.ToString() + "','" + altNo + "', '"
                                                                  + qty + "');";
                                        cmd.CommandText = StrQueryLLDetail;
                                        cmd.ExecuteNonQuery();
                                    }
                                    else
                                    {
                                        //update location
                                        loc = dataGridViewLL.Rows[j].Cells[4].Value.ToString();

                                        string StrQueryAddLoc = "UPDATE tbl_reel SET loc = CONCAT(loc,'" + loc + "') " +
                                                                "WHERE reel = '" + reelID + "' AND tbl_reel.WO_ptsn = '" + woPTSN + "' and tbl_reel.process_Name = '" + process + "'";
                                        cmd.CommandText = StrQueryAddLoc;
                                        cmd.ExecuteNonQuery();
                                    }
                                }

                                connection.Close();
                                //Tutup koneksi
                                CloseProgress();

                                MessageBox.Show("Loading List Successfully saved", "Loading List", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                saveButton.Enabled = true;
                                backButton.Enabled = true;

                                cmbProcess.Items.Remove(cmbProcess.SelectedItem);
                                filepathLL.Text           = "";
                                tbModel.Text              = "";
                                tbPWBType.Text            = "";
                                tbMachine.Text            = "";
                                tbProg.Text               = "";
                                tbRev.Text                = "";
                                tbPcbNo.Text              = "";
                                tbStencil.Text            = "";
                                totalPoint.Text           = "";
                                totalPart.Text            = "";
                                dataGridViewLL.DataSource = null;
                                dataGridViewLL.Refresh();

                                var count = cmbProcess.Items.Count;

                                if (count > 0)
                                {
                                    MessageBox.Show("Continue Import Other Process", "Loading List", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    cmbProcess.SelectedItem = cmbProcess.Items[0];
                                }
                                else if (count == 0)
                                {
                                    string            message = "Do you want to compare this Loading List ?";
                                    string            title   = "Compare WO vs LL";
                                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                                    DialogResult      result  = MessageBox.Show(message, title, buttons);
                                    if (result == DialogResult.Yes)
                                    {
                                        Compare cowl = new Compare();
                                        //cowl.cmbWOModel.SelectedItem = cowl.cmbWOModel.Items[0];
                                        cowl.cmbWOPtsn.SelectedItem = tbWoPTSN.Text;
                                        cowl.Show();
                                        this.Hide();
                                    }
                                    else
                                    {
                                        LoadingList ll = new LoadingList();
                                        ll.Show();
                                        this.Hide();
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        CloseProgress();
                        connection.Close();
                        MessageBox.Show(ex.Message.ToString());
                        backButton.Enabled = true;
                        saveButton.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
Exemplo n.º 2
0
        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
                {
                }
            }
        }