Example #1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Rows[e.RowIndex].Cells[1].Value == null)
            {
                return;
            }


            if (e.ColumnIndex == dataGridView1.Columns["Delete"].Index && e.RowIndex >= 0 && dataGridView1.Rows.Count > 0)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure to delete " + this.dataGridView1.Rows[e.RowIndex].Cells[1].Value + " , " + this.dataGridView1.Rows[e.RowIndex].Cells[2].Value + "Kg ?", "Delete", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    Int32  n          = e.RowIndex;
                    Int32  id         = 0;
                    String intlotcode = lblInternalcode.Text.Trim();

                    MainMenu        frm  = new MainMenu();
                    List <object[]> data = new List <object[]>();

                    if (textBox1.Text.Equals(""))
                    {
                        data = frm.get_data_table_string_byid_desc("tbcuttingdetails", "intlotcode", intlotcode);
                    }
                    else
                    {
                        data = frm.get_data_table_search("tbcuttingdetails", lblInternalcode.Text.Trim(), textBox1.Text.Trim());
                    }

                    //get_data_table_search(String tablename, String intlotcode, String value)

                    //data = frm.get_data_table_transaction("tbcuttingdetails", intlotcode, "seq1", "seq2");
                    for (int i = 0; i <= n; i++)
                    {
                        if (i == n)
                        {
                            id = Int32.Parse(data[i][0].ToString());
                        }
                    }

                    //frm.delete_table("tbcuttingdetails", "id", id.ToString());
                    String          connString = Konek();
                    MySqlConnection conn5      = new MySqlConnection(connString);
                    conn5.Open();
                    try
                    {
                        MySqlCommand mySql3 = conn5.CreateCommand();
                        mySql3.CommandText = "update tbcuttingdetails  set tipe=@tipe,grade=@grade,cweight=0,intlotcode=@intlotcode, moddatetime=@moddatetime where id=@id";
                        mySql3.Parameters.AddWithValue("@tipe", "");
                        mySql3.Parameters.AddWithValue("@grade", "");
                        mySql3.Parameters.AddWithValue("@intlotcode", "4del");
                        mySql3.Parameters.AddWithValue("@moddatetime", frm.get_server_time());
                        mySql3.Parameters.AddWithValue("@id", id.ToString());
                        mySql3.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    if (textBox1.Text.Equals(""))
                    {
                        loaddatacutdet();
                    }
                    else
                    {
                        loaddatasearch(textBox1.Text.Trim());
                    }
                }
            }


            if (e.ColumnIndex == dataGridView1.Columns["Edit"].Index && e.RowIndex >= 0 && dataGridView1.Rows.Count > 0)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure to Edit " + this.dataGridView1.Rows[e.RowIndex].Cells[1].Value + " , " + this.dataGridView1.Rows[e.RowIndex].Cells[2].Value + "Kg ?", "Edit", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    Int32    n          = e.RowIndex;
                    Int32    id         = 0;
                    String   intlotcode = lblInternalcode.Text.Trim();
                    MainMenu frm        = new MainMenu();

                    List <object[]> data = new List <object[]>();
                    if (textBox1.Text.Equals(""))
                    {
                        data = frm.get_data_table_string_byid_desc("tbcuttingdetails", "intlotcode", intlotcode);
                    }
                    else
                    {
                        data = frm.get_data_table_search("tbcuttingdetails", lblInternalcode.Text.Trim(), textBox1.Text.Trim());
                    }

                    for (int i = 0; i <= n; i++)
                    {
                        if (i == n)
                        {
                            id         = Int32.Parse(data[i][0].ToString());
                            lblid.Text = id.ToString();
                        }
                    }
                    panel1.Visible     = true;
                    txtgrade.Text      = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                    txtweightedit.Text = this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                }
            }
        }