Ejemplo n.º 1
0
        private void DisplayMauBaoCao()
        {
            Cursor.Current = Cursors.WaitCursor;
            if (cboLoaiSieuAm.Text.Trim() == string.Empty)
            {
                _textControl.ResetContents();
                return;
            }

            if (_loaiSieuAmGUID != string.Empty && _htMauBaoCao.ContainsKey(_loaiSieuAmGUID))
            {
                byte[] buff = null;
                _textControl.Save(out buff, TXTextControl.BinaryStreamType.MSWord);
                _htMauBaoCao[_loaiSieuAmGUID] = buff;
            }


            bool isNam = _gioiTinh.ToLower() == "nam" ? true : false;

            _loaiSieuAmGUID = cboLoaiSieuAm.SelectedValue.ToString();
            Result result = SieuAmBus.GetMauBaoCao(_loaiSieuAmGUID, isNam);

            if (!result.IsOK)
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("SieuAmBus.GetMauBaoCao"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("SieuAmBus.GetMauBaoCao"));
            }
            else
            {
                MauBaoCao mauBaoCao = result.QueryResult as MauBaoCao;
                if (mauBaoCao == null)
                {
                    _textControl.ResetContents();
                }
                else
                {
                    byte[] buff = null;
                    if (!_htMauBaoCao.ContainsKey(_loaiSieuAmGUID))
                    {
                        buff = mauBaoCao.Template.ToArray();
                        _htMauBaoCao.Add(_loaiSieuAmGUID, buff);
                    }
                    else
                    {
                        buff = (byte[])_htMauBaoCao[_loaiSieuAmGUID];
                    }

                    _textControl.Load(buff, TXTextControl.BinaryStreamType.MSWord);
                }
            }
        }
Ejemplo n.º 2
0
        public static Result GetMauBaoCao(string loaiSieuAmGUID, bool isNam)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                MauBaoCao mauBaoCao = null;
                if (isNam)
                {
                    mauBaoCao = (from m in db.MauBaoCaos
                                 where m.LoaiSieuAmGUID.ToString() == loaiSieuAmGUID && m.Status == (byte)Status.Actived &&
                                 (m.DoiTuong == (byte)DoiTuong.Chung || m.DoiTuong == (byte)DoiTuong.Nam)
                                 select m).FirstOrDefault();
                }
                else
                {
                    mauBaoCao = (from m in db.MauBaoCaos
                                 where m.LoaiSieuAmGUID.ToString() == loaiSieuAmGUID && m.Status == (byte)Status.Actived &&
                                 (m.DoiTuong == (byte)DoiTuong.Chung || m.DoiTuong == (byte)DoiTuong.Nu)
                                 select m).FirstOrDefault();
                }

                result.QueryResult = mauBaoCao;
            }
            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);
        }
Ejemplo n.º 3
0
        private void OnEdit()
        {
            _isNew = false;
            if (_drLoaiSieuAm == null)
            {
                MsgBox.Show(Application.ProductName, "Vui lòng chọn loại siêu âm cần cập nhật.", IconType.Information);
                return;
            }

            if (!CheckInfo())
            {
                return;
            }

            LoaiSieuAm loaiSieuAm = new LoaiSieuAm();

            loaiSieuAm.LoaiSieuAmGUID = Guid.Parse(_drLoaiSieuAm["LoaiSieuAmGUID"].ToString());
            loaiSieuAm.UpdatedBy      = Guid.Parse(Global.UserGUID);
            loaiSieuAm.UpdatedDate    = DateTime.Now;
            loaiSieuAm.TenSieuAm      = txtTenSieuAm.Text.Trim();
            loaiSieuAm.ThuTu          = (int)numThuTu.Value;
            loaiSieuAm.InTrang2       = chkInTrang2.Checked;
            loaiSieuAm.Status         = (byte)Status.Actived;

            List <MauBaoCao> mauBaoCaoList = new List <MauBaoCao>();

            byte[] buff = null;
            _textControl1.Save(out buff, TXTextControl.BinaryStreamType.MSWord);
            MauBaoCao mauBaoCao = new MauBaoCao();

            mauBaoCao.Template = new System.Data.Linq.Binary(buff);
            mauBaoCao.DoiTuong = (int)DoiTuong.Chung;


            if (raNamNu.Checked)
            {
                if (chkNam.Checked)
                {
                    mauBaoCao.DoiTuong = (int)DoiTuong.Nam;
                    mauBaoCaoList.Add(mauBaoCao);
                }

                if (chkNu.Checked)
                {
                    buff = null;
                    _textControl2.Save(out buff, TXTextControl.BinaryStreamType.MSWord);
                    mauBaoCao          = new MauBaoCao();
                    mauBaoCao.Template = new System.Data.Linq.Binary(buff);
                    mauBaoCao.DoiTuong = (int)DoiTuong.Nu;

                    mauBaoCaoList.Add(mauBaoCao);
                }
            }
            else
            {
                mauBaoCaoList.Add(mauBaoCao);
            }

            Result result = SieuAmBus.InsertLoaiSieuAm(loaiSieuAm, mauBaoCaoList);

            if (result.IsOK)
            {
                _flag = true;
                OnDisplayLoaiSieuList();
                _flag = false;

                SetCurrentLoaiSieuAm(loaiSieuAm.LoaiSieuAmGUID.ToString());
            }
            else
            {
                MsgBox.Show(Application.ProductName, result.GetErrorAsString("SieuAmBus.InsertLoaiSieuAm"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("SieuAmBus.InsertLoaiSieuAm"));
            }
        }
Ejemplo n.º 4
0
        public static Result InsertLoaiSieuAm(LoaiSieuAm loaiSieuAm, List <MauBaoCao> mauBaoCaoList)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (loaiSieuAm.LoaiSieuAmGUID == null || loaiSieuAm.LoaiSieuAmGUID == Guid.Empty)
                    {
                        loaiSieuAm.LoaiSieuAmGUID = Guid.NewGuid();
                        db.LoaiSieuAms.InsertOnSubmit(loaiSieuAm);
                        db.SubmitChanges();

                        foreach (var mauBaoCao in mauBaoCaoList)
                        {
                            mauBaoCao.MauBaoCaoGUID  = Guid.NewGuid();
                            mauBaoCao.LoaiSieuAmGUID = loaiSieuAm.LoaiSieuAmGUID;
                            mauBaoCao.CreatedDate    = DateTime.Now;
                            mauBaoCao.CreatedBy      = Guid.Parse(Global.UserGUID);
                            db.MauBaoCaos.InsertOnSubmit(mauBaoCao);
                        }

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Tên siêu âm: '{1}', Thứ tự: '{2}', In trang 2: '{3}'",
                                              loaiSieuAm.LoaiSieuAmGUID.ToString(), loaiSieuAm.TenSieuAm, loaiSieuAm.ThuTu, loaiSieuAm.InTrang2);

                        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 loại siêu âm";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        LoaiSieuAm lsa = db.LoaiSieuAms.SingleOrDefault <LoaiSieuAm>(s => s.LoaiSieuAmGUID.ToString() == loaiSieuAm.LoaiSieuAmGUID.ToString());
                        if (lsa != null)
                        {
                            lsa.TenSieuAm   = loaiSieuAm.TenSieuAm;
                            lsa.ThuTu       = loaiSieuAm.ThuTu;
                            lsa.InTrang2    = loaiSieuAm.InTrang2;
                            lsa.Path        = loaiSieuAm.Path;
                            lsa.UpdatedDate = loaiSieuAm.UpdatedDate;
                            lsa.UpdatedBy   = loaiSieuAm.UpdatedBy;
                            lsa.Status      = loaiSieuAm.Status;

                            //Delete mẫu báo cáo
                            var mbcs = lsa.MauBaoCaos;
                            foreach (var mbc in mbcs)
                            {
                                mbc.UpdatedBy   = Guid.Parse(Global.UserGUID);
                                mbc.UpdatedDate = DateTime.Now;
                                mbc.Status      = (byte)Status.Deactived;
                            }

                            //Update mẫu báo cáo
                            foreach (var mbc in mauBaoCaoList)
                            {
                                MauBaoCao mauBaoCao = lsa.MauBaoCaos.Where(m => m.DoiTuong == mbc.DoiTuong).FirstOrDefault();
                                if (mauBaoCao == null)
                                {
                                    mbc.MauBaoCaoGUID  = Guid.NewGuid();
                                    mbc.LoaiSieuAmGUID = loaiSieuAm.LoaiSieuAmGUID;
                                    mbc.CreatedDate    = DateTime.Now;
                                    mbc.CreatedBy      = Guid.Parse(Global.UserGUID);
                                    db.MauBaoCaos.InsertOnSubmit(mbc);
                                }
                                else
                                {
                                    mauBaoCao.UpdatedBy   = Guid.Parse(Global.UserGUID);
                                    mauBaoCao.UpdatedDate = DateTime.Now;
                                    mauBaoCao.Template    = mbc.Template;
                                    mauBaoCao.Status      = (byte)Status.Actived;
                                }
                            }

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Tên siêu âm: '{1}', Thứ tự: '{2}', In trang 2: '{3}'",
                                                  lsa.LoaiSieuAmGUID.ToString(), lsa.TenSieuAm, lsa.ThuTu, lsa.InTrang2);

                            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 loại siêu âm";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            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);
        }