示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtName.Text))
            {
                XtraMessageBox.Show("Bạn Chưa Nhập Tên Mặt Hàng !");
                txtName.Focus();
                return;
            }
            if (String.IsNullOrEmpty(cbbGroupItem.Text))
            {
                XtraMessageBox.Show("Bạn Chưa Chọn Nhóm Mặt Hàng !");
                cbbGroupItem.Focus();
                return;
            }
            if (String.IsNullOrEmpty(cbbUnit.Text))
            {
                XtraMessageBox.Show("Bạn Chưa Chọn Đơn Vị Tính !");
                cbbUnit.Focus();
                return;
            }
            if (IdItem != null)
            {
                //Cap nhat lai mat hang
                bool flagUpdate = _item.UpdateItems(txtID.Text, cbbGroupItem.SelectedValue.ToString(), cbbUnit.SelectedValue.ToString(), txtName.Text, txtPriceOut.Text, txtRose.Text, txtRoseRate.Text);
                if (flagUpdate)
                {
                    if (dgv_ContentItem.Rows.Count > 0)
                    {
                        //Co roi thi cap nhat so luong(neu co)
                        for (int m = 0; m < dgv_ContentItem.Rows.Count; m++)
                        {
                            bool flagUpdateCt = _item.UpdateContentItems(txtID.Text, dgv_ContentItem.Rows[m].Cells["ID"].Value.ToString(), dgv_ContentItem.Rows[m].Cells["NUMBER"].Value.ToString());
                        }
                        //chua co thi them vao
                        for (int i = 0; i < dgv_ContentItem.Rows.Count; i++)
                        {
                            bool flagUpdateAddCt = _item.AddContentItems(txtID.Text, dgv_ContentItem.Rows[i].Cells["ID"].Value.ToString(), dgv_ContentItem.Rows[i].Cells["NUMBER"].Value.ToString());
                        }
                    }
                    //Xoa neu co
                    for (int j = 0; j < listDelete.Count; j++)
                    {
                        bool flagUpdateDeleteCt = _item.DeleteContentItems(txtID.Text, listDelete[j].ToString());
                    }
                }
                XtraMessageBox.Show("Cập Nhật Mặt Hàng Thành Công !");
                return;
            }
            //Them mot mat hang moi (mat hang co the la goi dich vu hoac la mot san pham cu the)
            //Doi voi goi dich vu co the co hoac khong co noi dung vat tu nao
            bool flagAdd = _item.AddItems(txtID.Text, cbbGroupItem.SelectedValue.ToString(), cbbUnit.SelectedValue.ToString(), txtName.Text, txtPriceOut.Text, txtRose.Text, txtRoseRate.Text);

            if (flagAdd)
            {
                //Them noi dung
                if (dgv_ContentItem.Rows.Count > 0)
                {
                    //Them
                    for (int i = 0; i < dgv_ContentItem.Rows.Count; i++)
                    {
                        bool flagAddCtent = _item.AddContentItems(txtID.Text, dgv_ContentItem.Rows[i].Cells["ID"].Value.ToString(), dgv_ContentItem.Rows[i].Cells["NUMBER"].Value.ToString());
                    }
                }
            }
            XtraMessageBox.Show("Thêm Mặt Hàng Thành Công !");
            return;
        }