Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            TienTraTruoc f4           = new TienTraTruoc();
            var          result       = f4.ShowDialog();
            Int64        tientratruoc = 0;

            if (result == DialogResult.OK)
            {
                tientratruoc = f4.ReturnValue1;
            }

            MySqlConnection connection = new MySqlConnection(MyConnectionMySQL);
            MySqlCommand    cmd, cmd2;

            connection.Open();
            //Lấy phân loại
            try
            {
                cmd2             = connection.CreateCommand();
                cmd2.CommandText = @"SELECT TienDaTra FROM hoadon WHERE MaHD = @MA";
                cmd2.Parameters.AddWithValue("@MA", mahoadon);

                Int64 res = Int64.Parse(cmd2.ExecuteScalar().ToString(), NumberStyles.AllowThousands);


                cmd             = connection.CreateCommand();
                cmd.CommandText = @"UPDATE hoadon SET TrangThai = @trangthai,TienDaTra = @datra WHERE MaHD = @MA";
                cmd.Parameters.AddWithValue("@MA", mahoadon);
                cmd.Parameters.AddWithValue("@datra", (tientratruoc + res).ToString("#,##0"));
                cmd.Parameters.AddWithValue("@trangthai", "Nợ");
                cmd.ExecuteNonQuery();
            }
            catch (Exception v)
            {
                MessageBox.Show(v.Message.ToString());
                //throw;
            }
            finally
            {
                connection.Close();
            }

            HienHoaDon f = new HienHoaDon(mahoadon);

            f.ShowDialog();

            this.Close();
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            MySqlConnection connection = new MySqlConnection(MyConnectionMySQL);
            MySqlCommand    cmd, cmd2;

            connection.Open();
            //Lấy phân loại
            try
            {
                cmd2             = connection.CreateCommand();
                cmd2.CommandText = @"SELECT TongTien FROM hoadon WHERE MaHD = @MA";
                cmd2.Parameters.AddWithValue("@MA", mahoadon);

                string s = cmd2.ExecuteScalar().ToString();

                cmd             = connection.CreateCommand();
                cmd.CommandText = @"UPDATE hoadon SET TrangThai = @trangthai,TienDaTra = @tongtien WHERE MaHD = @MA";
                cmd.Parameters.AddWithValue("@MA", mahoadon);
                cmd.Parameters.AddWithValue("@tongtien", s);
                cmd.Parameters.AddWithValue("@trangthai", "Hoàn tất");
                cmd.ExecuteNonQuery();
                this.Close();
            }
            catch (Exception v)
            {
                MessageBox.Show(v.Message.ToString());
                //throw;
            }
            finally
            {
                connection.Close();
            }
            HienHoaDon f = new HienHoaDon(mahoadon);

            f.ShowDialog();
        }