Пример #1
0
        private void UpdateData()
        {
            SQLiteDAL DAL = new SQLiteDAL();
            DAL.BeginTransaction();
            clsBangKe objBangKe = new clsBangKe();
            List<clsBangKeChiTiet> chitiets = new List<clsBangKeChiTiet>();

            try
            {
                objBangKe.GetByKey(m_BangKe_Id);

                FillBangKe(ref objBangKe);
                int kq = objBangKe.Update(DAL);

                if (kq > 0)
                {
                    kq = objBangKe.DeleteBangKeChiTiet(m_BangKe_Id, DAL);
                    if (kq > 0)
                    {
                        FillBangKe(ref chitiets, m_BangKe_Id);
                        foreach (clsBangKeChiTiet ct in chitiets)
                        {
                            kq = ct.Insert(DAL);
                            if (kq <= 0)
                            {
                                DAL.RollbackTransaction();
                                return;
                            }
                        }
                    }
                    else
                    {
                        DAL.RollbackTransaction();
                        return;
                    }

                }
                else
                {
                    DAL.RollbackTransaction();
                    return;
                }

                DAL.CommitTransaction();
                //MessageBox.Show("Cập nhật bảng kê thành công", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                lblThongBao.Text = "Cập nhật bảng kê thành công.";
                timerThongBao.Enabled = true;
            }
            catch (Exception ex)
            {
                DAL.RollbackTransaction();
                m_BangKe_Id = 0;
                txtSoHoSo.Text = "";
                MessageBox.Show("Cập nhật bảng kê không thành công.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                //lblThongBao.Text = "Cập nhật bảng kê không thành công";
                //timerThongBao.Enabled = true;
            }
        }
        private void InsertDanhMucOnline()
        {
            //btnLamMoi.Enabled = false;
            //btnThem.Enabled = false;
            //btnXoa.Enabled = false;
            //btnLamMoi.Enabled = false;
            //btnGetDM.Enabled = false;
            //btnSua.Enabled = false;

            SystemConfig system = SystemConfig.Instance;
            string token = system.GetToken();
            if (string.IsNullOrEmpty(token))
            {
                MessageBox.Show("Vui lòng kiểm tra lại thông tin cấu hình!.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!string.IsNullOrEmpty(token))
            {
                string URL = clsGetMa.GetTenThamSoWS();
                string response = system.SendRequest(URL, "GET", string.Empty); //HttpRequest.WSRequest(URL1, "GET", string.Empty, token);
                if (string.IsNullOrEmpty(response))
                {
                    MessageBox.Show("Không lấy được dữ liệu.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                //string str = XMLUtils.DeSerializeToObject<string>(response);
                List<object> lstDMThuoc = clsGetMa.LayDanhSachFromWS(response);// XMLUtils.DeSerializeToList<DM_CSKCB>(response1);
                int tongRecord = lstDMThuoc.Count;
            //                "Có " + tongRecord + " danh mục thuốc. Bạn có muốn tải về?"
                if (MessageBox.Show(clsGetMa .ShowMessageGetDuLieu(tongRecord), "Thông báo", MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.No)
                {
                    return;
                }

                SQLiteDAL DAL = new SQLiteDAL();
                 DAL.BeginTransaction();
               //  hst.Delete();
                foreach (object t in lstDMThuoc)
                {
                   int result= clsGetMa.XuLyTuWSSangCSDL(t,dtDM,DAL);

                   if (result == 0)
                   {
                       DAL.RollbackTransaction();
                       return;
                   }

                }
              //  Close & Commit Trans
                DAL.CommitTransaction();

                LoadGridview();
                MessageBox.Show("Đã Lấy Dữ Liệu Thành Công.");
                //btnLamMoi.Enabled = true;
                //btnThem.Enabled = true;
                //btnXoa.Enabled = true;
                //btnLamMoi.Enabled = true;
                //btnGetDM.Enabled = true;
                //btnSua.Enabled = true;
            }
            else
            {
                // "Access token is empty.";
            }
        }
Пример #3
0
        private void InsertData()
        {
            SQLiteDAL DAL = new SQLiteDAL();
            DAL.BeginTransaction();
            clsBangKe objBangKe = new clsBangKe();
            List<clsBangKeChiTiet> chitiets = new List<clsBangKeChiTiet>();
            try
            {
                FillBangKe(ref objBangKe);
                int intBangKe_Id = objBangKe.Insert(DAL);

                m_BangKe_Id = intBangKe_Id;

                int kq = 0;
                if (intBangKe_Id > 0)
                {

                    FillBangKe(ref chitiets, intBangKe_Id);
                    foreach (clsBangKeChiTiet ct in chitiets)
                    {
                        kq = ct.Insert(DAL);
                        if (kq <= 0)
                        {
                            DAL.RollbackTransaction();
                            return;
                        }
                    }
                }
                else
                {
                    DAL.RollbackTransaction();
                    return;
                }

                DAL.CommitTransaction();
                //MessageBox.Show("Thêm mới bảng kê thành công", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                lblThongBao.Text = "Thêm mới bảng kê thành công.";
                timerThongBao.Enabled = true;
            }
            catch (Exception ex)
            {
                DAL.RollbackTransaction();
                MessageBox.Show("Thêm mới bảng kê không thành công.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                //lblThongBao.Text = "Thêm mới bảng kê không thành công";
                //timerThongBao.Enabled = true;
            }
        }