Esempio n. 1
0
        public static Result InsertGiaCapCuu(GiaCapCuu giaCapCuu)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;

                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (giaCapCuu.GiaCapCuuGUID == null || giaCapCuu.GiaCapCuuGUID == Guid.Empty)
                    {
                        giaCapCuu.GiaCapCuuGUID = Guid.NewGuid();
                        db.GiaCapCuus.InsertOnSubmit(giaCapCuu);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Cấp cứu: '{1}', Giá bán: '{2}', Ngày áp dụng: '{3}'",
                                              giaCapCuu.GiaCapCuuGUID.ToString(), giaCapCuu.KhoCapCuu.TenCapCuu, giaCapCuu.GiaBan, giaCapCuu.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss"));

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin giá cấp cứu";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.Price;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        GiaCapCuu gt = db.GiaCapCuus.SingleOrDefault <GiaCapCuu>(g => g.GiaCapCuuGUID == giaCapCuu.GiaCapCuuGUID);
                        if (gt != null)
                        {
                            double giaCu = gt.GiaBan;

                            gt.KhoCapCuuGUID = giaCapCuu.KhoCapCuuGUID;
                            gt.GiaBan        = giaCapCuu.GiaBan;
                            gt.NgayApDung    = giaCapCuu.NgayApDung;
                            gt.Note          = giaCapCuu.Note;
                            gt.CreatedDate   = giaCapCuu.CreatedDate;
                            gt.CreatedBy     = giaCapCuu.CreatedBy;
                            gt.UpdatedDate   = giaCapCuu.UpdatedDate;
                            gt.UpdatedBy     = giaCapCuu.UpdatedBy;
                            gt.DeletedDate   = giaCapCuu.DeletedDate;
                            gt.DeletedBy     = giaCapCuu.DeletedBy;
                            gt.Status        = giaCapCuu.Status;
                            db.SubmitChanges();

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Cấp cứu: '{1}', Giá bán: cũ: '{2}' - mới: '{3}', Ngày áp dụng: '{4}'",
                                                  gt.GiaCapCuuGUID.ToString(), gt.KhoCapCuu.TenCapCuu, giaCu, gt.GiaBan, gt.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss"));

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin giá cấp cứu";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.Price;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Esempio n. 2
0
        public static Result DeleteGiaCapCuu(List <string> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in keys)
                    {
                        GiaCapCuu giaCapCuu = db.GiaCapCuus.SingleOrDefault <GiaCapCuu>(g => g.GiaCapCuuGUID.ToString() == key);
                        if (giaCapCuu != null)
                        {
                            giaCapCuu.DeletedDate = DateTime.Now;
                            giaCapCuu.DeletedBy   = Guid.Parse(Global.UserGUID);
                            giaCapCuu.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Cấp cứu: '{1}', Giá bán: '{2}', Ngày áp dụng: '{3}'\n",
                                                  giaCapCuu.GiaCapCuuGUID.ToString(), giaCapCuu.KhoCapCuu.TenCapCuu, giaCapCuu.GiaBan, giaCapCuu.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss"));
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin giá cấp cứu";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.Price;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }