Exemple #1
0
        private void frmQuanLyKho_Load(object sender, EventArgs e)
        {
            this.CenterToScreen();

            cbbTieuChiTimKiem.Text = "Tên Gạo";
            KetNoiSQL.LoadDLQLTTGao(dataViewQLTTG);
            Disable_TTGao();
        }
Exemple #2
0
        private void btXoa_Click(object sender, EventArgs e)
        {
            EmptyTTGao();
            SqlConnection conn = SQLDatabase.GetDBConnection();

            conn.Open();
            try
            {
                if (MessageBox.Show("Bạn chắc chắn muốn xóa Thông Tin Gạo đã chọn?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    int dem = 0;
                    foreach (DataGridViewRow row in dataViewQLTTG.Rows)
                    {
                        if (row.Cells[0].Value != null)
                        {
                            if ((bool)row.Cells[0].Value == true)
                            {
                                dem++;
                                string     MaGao           = row.Cells[1].Value.ToString();
                                string     sqldelete_QLTTG = "DELETE FROM GAO WHERE MAGAO = @MaGao";
                                SqlCommand command1        = new SqlCommand(sqldelete_QLTTG, conn);
                                command1.Parameters.AddWithValue("@MaGao", MaGao);
                                command1.ExecuteNonQuery();
                            }
                        }
                    }
                    if (dem == 0)
                    {
                        MessageBox.Show("Bạn chưa chọn Thông Tin Gạo để xóa!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        string strThongBao = "Xóa " + dem + " Thông Tin Gạo thành công!";
                        MessageBox.Show(strThongBao, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    KetNoiSQL.LoadDLQLTTGao(dataViewQLTTG);
                }
            }
            catch
            {
                MessageBox.Show("Xóa Thông Tin Gạo không thành công\nVui lòng kiểm tra lại", "LỖI", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }
        }
Exemple #3
0
        private void btDongY_Sua_Click(object sender, EventArgs e)
        {
            SqlConnection conn = SQLDatabase.GetDBConnection();

            conn.Open();
            if (txtMaGao.Text == "")
            {
                MessageBox.Show("Cập nhật Thông Tin Gạo không thành công\nVui lòng kiểm tra lại Mã Gạo", "CẢNH BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (txtTenGao.Text == "" || cbbLoaiGao.Text == "" || txtTrongLuong.Text == "" || txtGiaNhap.Text == "" || txtGiaBan.Text == "" || txtXuatXu.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                try
                {
                    Double     TrongLuong = Double.Parse(txtTrongLuong.Text);
                    string     sql1       = "UPDATE GAO SET TENGAO = @TenGao, LOAIGAO = @LoaiGao, TRONGLUONGGAO = @TrongLuongGao, GIANHAP = @GiaNhap, GIABAN = @GiaBan, XUATXU = @XuatXu WHERE MAGAO = @MaGao";
                    SqlCommand command1   = new SqlCommand(sql1, conn);
                    command1.Parameters.AddWithValue("@MaGao", txtMaGao.Text);
                    command1.Parameters.AddWithValue("@TenGao", txtTenGao.Text);
                    command1.Parameters.AddWithValue("@LoaiGao", cbbLoaiGao.Text);
                    command1.Parameters.AddWithValue("@TrongLuongGao", TrongLuong);
                    command1.Parameters.AddWithValue("@GiaNhap", txtGiaNhap.Text);
                    command1.Parameters.AddWithValue("@GiaBan", txtGiaBan.Text);
                    command1.Parameters.AddWithValue("@XuatXu", txtXuatXu.Text);
                    command1.ExecuteNonQuery();

                    MessageBox.Show("Cập nhật Thông Tin Gạo thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    KetNoiSQL.LoadDLQLTTGao(dataViewQLTTG);
                }
                catch
                {
                    MessageBox.Show("Cập nhật Thông Tin Gạo không thành công..\nVui lòng kiểm tra lại.", "LỖI", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Exemple #4
0
        private void ThemMoiGao()
        {
            SqlConnection conn = SQLDatabase.GetDBConnection();

            conn.Open();

            if (txtMaGao.Text == "")
            {
                MessageBox.Show("Thêm mới Thông Tin Gạo không thành công\nVui lòng nhập thông tin Mã Gạo", "CẢNH BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                try
                {
                    int check = CheckExistence("MAGAO", txtMaGao.Text);

                    //Nhập mới;
                    if (check == 0)
                    {
                        if (txtTenGao.Text == "" || cbbLoaiGao.Text == "" || txtTrongLuong.Text == "" || txtGiaNhap.Text == "" || txtGiaBan.Text == "" || txtXuatXu.Text == "")
                        {
                            MessageBox.Show("Thêm mới Thông Tin Gạo không thành công\nVui lòng nhập đầy đủ thông tin", "CẢNH BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            string     sql2     = "INSERT INTO GAO(MAGAO,TENGAO,LOAIGAO,TRONGLUONGGAO,GIANHAP,GIABAN,XUATXU) VALUES(@MaGao,@TenGao,@LoaiGao,@TrongLuongGao,@GiaNhap,@GiaBan,@XuatXu)";
                            SqlCommand command2 = new SqlCommand(sql2, conn);
                            command2.Parameters.AddWithValue("@MaGao", txtMaGao.Text);
                            command2.Parameters.AddWithValue("@TenGao", txtTenGao.Text);
                            command2.Parameters.AddWithValue("@LoaiGao", cbbLoaiGao.Text);
                            command2.Parameters.AddWithValue("@TrongLuongGao", txtTrongLuong.Text);
                            command2.Parameters.AddWithValue("@GiaNhap", txtGiaNhap.Text);
                            command2.Parameters.AddWithValue("@GiaBan", txtGiaBan.Text);
                            command2.Parameters.AddWithValue("@XuatXu", txtXuatXu.Text);
                            command2.ExecuteNonQuery();
                            MessageBox.Show("Thêm Thông Tin Gạo mới thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            KetNoiSQL.LoadDLQLTTGao(dataViewQLTTG);
                        }
                    }
                    //Cập nhật;
                    else
                    {
                        Double        tempTrongLuong = 0;
                        string        TenGao         = "";
                        string        sql3           = "SELECT * FROM GAO WHERE GAO.MAGAO = '" + txtMaGao.Text + "'";
                        SqlCommand    command3       = new SqlCommand(sql3, conn);
                        SqlDataReader reader         = command3.ExecuteReader();
                        while (reader.Read())
                        {
                            TenGao         = reader.GetString(1);
                            tempTrongLuong = reader.GetDouble(3);
                        }

                        reader.Close();

                        Double temp = Double.Parse(txtTrongLuong.Text);

                        Double TrongLuong = (tempTrongLuong + temp);

                        //txtXuatXu.Text = TrongLuong;

                        string     sql4     = "UPDATE GAO SET TRONGLUONGGAO = @TrongLuongGao WHERE MAGAO = @MaGao";
                        SqlCommand command4 = new SqlCommand(sql4, conn);
                        command4.Parameters.AddWithValue("@MaGao", txtMaGao.Text);
                        command4.Parameters.AddWithValue("@TrongLuongGao", TrongLuong);
                        command4.ExecuteNonQuery();
                        string str = "Gạo '" + TenGao + "' vừa được nhập thêm '" + txtTrongLuong.Text + "' KG";
                        MessageBox.Show(str, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        KetNoiSQL.LoadDLQLTTGao(dataViewQLTTG);
                    }
                }
                catch
                {
                    MessageBox.Show("Không thành công\nVui lòng kiểm tra lại", "LỖI", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
        }