コード例 #1
0
        private void btn_Sua_Click(object sender, EventArgs e)
        {
            if (!editMode)
            {
                editMode            = true;
                txt_ten.Enabled     = true;
                txt_tien.Enabled    = true;
                txt_SoLuong.Enabled = true;
            }
            else
            {
                if (string.IsNullOrWhiteSpace(txt_ten.Text))
                {
                    MessageBox.Show("Chưa nhập tên khoản chi", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (string.IsNullOrWhiteSpace(txt_tien.Text))
                {
                    MessageBox.Show("Chưa nhập số tiền", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (string.IsNullOrWhiteSpace(txt_SoLuong.Text))
                {
                    MessageBox.Show("Chưa nhập số lượng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (cbb_loaikhoanchi.SelectedIndex == -1)
                {
                    MessageBox.Show("Chưa chọn loại khoản chi", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (cbb_type.SelectedIndex == -1)
                {
                    MessageBox.Show("Chưa nhập mã khoản chi", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    string mathu1     = guna2DataGridView1.CurrentRow.Cells[0].Value.ToString();
                    string loai       = (cbb_loaikhoanchi.SelectedIndex + 1).ToString();
                    string magiaovien = LoginUser.UserData()["manv"].ToString();

                    DataController.Execute("update tttienchi set " +
                                           "soluong = " + txt_SoLuong.Text +
                                           ", thanhtien = " + txt_tien.Text +
                                           ", tentienchi = N'" + txt_ten.Text + "'" +
                                           "where matttc = " + mathu1);

                    guna2DataGridView1.DataSource = DataController.ExecTable("select " +
                                                                             "matttc, " +
                                                                             "tentienchi, " +
                                                                             "soluong, " +
                                                                             "thanhtien, " +
                                                                             "thoigian, " +
                                                                             "tennv " +
                                                                             "from tttienchi " +
                                                                             "inner join nhanvien on tttienchi.manv = nhanvien.manv");


                    editMode            = false;
                    btn_Sua.Enabled     = true;
                    btn_Xoa.Enabled     = true;
                    btn_HuyThem.Visible = false;

                    txt_ten.Enabled          = false;
                    txt_tien.Enabled         = false;
                    txt_SoLuong.Enabled      = false;
                    cbb_loaikhoanchi.Enabled = false;
                    txt_GhiChu.Enabled       = false;
                    cbb_loaikhoanchi.Enabled = false;
                    cbb_type.Enabled         = false;


                    DataTable dt   = DataController.ExecTable("select * from tttienchi where matttc = " + mathu1);
                    DataRow   data = dt.Rows[0];

                    txt_ten.Text     = data["tentienchi"].ToString();
                    txt_tien.Text    = data["thanhtien"].ToString();
                    txt_SoLuong.Text = data["soluong"].ToString();
                    if (!data.IsNull("manguyenlieu"))
                    {
                        cbb_loaikhoanchi.SelectedIndex = 0;
                        cbb_type.SelectedIndex         = int.Parse(data["manguyenlieu"].ToString()) - 1;
                    }
                    else if (!data.IsNull("mahoclieu"))
                    {
                        cbb_loaikhoanchi.SelectedIndex = 1;
                        cbb_type.SelectedIndex         = int.Parse(data["mahoclieu"].ToString()) - 1;
                    }
                    else if (!data.IsNull("mahdnk"))
                    {
                        cbb_loaikhoanchi.SelectedIndex = 2;
                        cbb_type.SelectedIndex         = int.Parse(data["mahdnk"].ToString()) - 1;
                    }
                }
            }
        }