Exemplo n.º 1
0
        public static PsReponse UpdatePhieuSangLoc(List <PSPhieuSangLoc> lstpsl)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                var account = db.PSPhieuSangLocs.FirstOrDefault();
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                foreach (var psl in lstpsl)
                {
                    var psldb = db.PSPhieuSangLocs.FirstOrDefault(p => p.IDPhieu == psl.IDPhieu);
                    if (psldb != null)
                    {
                        var term = psl.RowIDPhieu;
                        psldb            = psl;
                        psldb.RowIDPhieu = term;
                        db.SubmitChanges();
                    }
                    else
                    {
                        PSPhieuSangLoc newpsl = new PSPhieuSangLoc();
                        newpsl            = psl;
                        newpsl.RowIDPhieu = 0;
                        newpsl.isDongBo   = true;
                        db.PSPhieuSangLocs.InsertOnSubmit(newpsl);
                        db.SubmitChanges();
                    }
                }

                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
Exemplo n.º 2
0
        public static PsReponse GetPhieuSangLoc()
        {
            PsReponse res = new PsReponse();

            res.Result = true;
            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                var account = db.PSAccount_Syncs.FirstOrDefault();
                if (account != null)
                {
                    string token = cn.GetToken(account.userName, account.passWord);
                    if (!string.IsNullOrEmpty(token))
                    {
                        var result = cn.GetRespone(cn.CreateLink(linkGetPhieuSangLoc), token);
                        if (result.Result)
                        {
                            string json = result.ValueResult;
                            JavaScriptSerializer jss = new JavaScriptSerializer();

                            ObjectModel.RootObjectAPI psl = jss.Deserialize <ObjectModel.RootObjectAPI>(json);
                            //List<PSPatient> patient = jss.Deserialize<List<PSPatient>>(json);
                            List <PSPhieuSangLoc> lstpsl = new List <PSPhieuSangLoc>();
                            if (psl.TotalCount > 0)
                            {
                                foreach (var item in psl.Items)
                                {
                                    PSPhieuSangLoc term = new PSPhieuSangLoc();
                                    term = cn.CovertDynamicToObjectModel(item, term);
                                    lstpsl.Add(term);
                                }
                                //UpdatePatient(patient);
                                UpdatePhieuSangLoc(lstpsl);
                                res.Result = true;
                            }
                        }
                        else
                        {
                            res.Result      = false;
                            res.StringError = result.ErorrResult;
                        }
                    }
                    else
                    {
                        res.Result      = false;
                        res.StringError = "Kiểm tra lại kết nối mạng hoặc tài khoản đồng bộ!";
                    }
                }
                else
                {
                    res.Result      = false;
                    res.StringError = "Chưa có  tài khoản đồng bộ!";
                }
            }
            catch (Exception ex)
            {
                res.Result      = false;
                res.StringError = DateTime.Now.ToString() + "Lỗi khi get dữ liệu Danh Mục Mapping Kỹ Thuật - Dịch Vụ từ server \r\n " + ex.Message;
            }
            return(res);
        }