Пример #1
0
        private void OnSaveInfo()
        {
            try
            {
                if (_isNew)
                {
                    _serviceHistory.CreatedDate = DateTime.Now;
                    _serviceHistory.CreatedBy = Guid.Parse(Global.UserGUID);
                }
                else
                {
                    _serviceHistory.UpdatedDate = DateTime.Now;
                    _serviceHistory.UpdatedBy = Guid.Parse(Global.UserGUID);
                }

                _serviceHistory.PatientGUID = Guid.Parse(_patientGUID);
                _serviceHistory.Note = txtDescription.Text;

                MethodInvoker method = delegate
                {
                    _serviceHistory.ActivedDate = dtpkActiveDate.Value;
                    _serviceHistory.KhamTuTuc = raKhamTuTuc.Checked;

                    if (cboDocStaff.SelectedValue != null && cboDocStaff.Text.Trim() != string.Empty)
                        _serviceHistory.DocStaffGUID = Guid.Parse(cboDocStaff.SelectedValue.ToString());
                    else
                        _serviceHistory.DocStaffGUID = null;

                    if (chkChuyenNhuong.Checked)
                        _serviceHistory.RootPatientGUID = Guid.Parse(txtChuyenNhuong.Tag.ToString());
                    else
                        _serviceHistory.RootPatientGUID = null;

                    _serviceHistory.ServiceGUID = Guid.Parse(cboService.SelectedValue.ToString());

                    _serviceHistory.Price = (double)numPrice.Value;
                    _serviceHistory.Discount = (double)numDiscount.Value;
                    _serviceHistory.SoLuong = Convert.ToInt32(numSoLuong.Value);

                    _serviceHistory.IsNormalOrNegative = raNormal.Checked;
                    if (raNormal.Checked)
                    {
                        _serviceHistory.Normal = chkNormal.Checked;
                        _serviceHistory.Abnormal = chkAbnormal.Checked;
                        _serviceHistory.Negative = false;
                        _serviceHistory.Positive = false;
                    }
                    else
                    {
                        _serviceHistory.Normal = false;
                        _serviceHistory.Abnormal = false;
                        _serviceHistory.Negative = chkNegative.Checked;
                        _serviceHistory.Positive = chkPositive.Checked;
                    }

                    if (_hopDongGUID != string.Empty)
                        _serviceHistory.HopDongGUID = Guid.Parse(_hopDongGUID);

                    Result result = GiaVonDichVuBus.GetGiaVonDichVuMoiNhat(_serviceHistory.ServiceGUID.ToString(), _serviceHistory.ActivedDate.Value);
                    if (!result.IsOK)
                    {
                        MsgBox.Show(this.Text, result.GetErrorAsString("GiaVonDichVuBus.GetGiaVonDichVuMoiNhat"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("GiaVonDichVuBus.GetGiaVonDichVuMoiNhat"));
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                        return;
                    }

                    DataTable dt = result.QueryResult as DataTable;
                    if (dt != null && dt.Rows.Count > 0)
                        _serviceHistory.GiaVon = Convert.ToDouble(dt.Rows[0]["GiaVon"]);

                    result = ServiceHistoryBus.InsertServiceHistory(_serviceHistory);
                    if (!result.IsOK)
                    {
                        MsgBox.Show(this.Text, result.GetErrorAsString("ServiceHistoryBus.InsertServiceHistory"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("ServiceHistoryBus.InsertServiceHistory"));
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    }
                    else if (_serviceGUID == string.Empty)
                    {
                        if (chkBSCD.Checked)
                        {
                            if (_chiDinh == null)
                            {
                                _chiDinh = new ChiDinh();
                                string maChiDinh = GenerateCode();
                                if (maChiDinh == string.Empty) return;

                                //Insert chỉ định
                                _chiDinh.CreatedDate = DateTime.Now;
                                _chiDinh.CreatedBy = Guid.Parse(Global.UserGUID);
                                _chiDinh.MaChiDinh = maChiDinh;
                                _chiDinh.BenhNhanGUID = Guid.Parse(_patientGUID);
                                _chiDinh.BacSiChiDinhGUID = Guid.Parse(cboBacSiChiDinh.SelectedValue.ToString());
                                _chiDinh.NgayChiDinh = DateTime.Now;
                                _chiDinh.Status = (byte)Status.Actived;

                                List<ChiTietChiDinh> addedList = new List<ChiTietChiDinh>();
                                List<string> deletedKeys = new List<string>();
                                ChiTietChiDinh ctcd = new ChiTietChiDinh();
                                ctcd.CreatedDate = DateTime.Now;
                                ctcd.CreatedBy = Guid.Parse(Global.UserGUID);
                                ctcd.ServiceGUID = _serviceHistory.ServiceGUID.Value;
                                addedList.Add(ctcd);

                                result = ChiDinhBus.InsertChiDinh(_chiDinh, addedList, deletedKeys);
                                if (!result.IsOK)
                                {
                                    MsgBox.Show(Application.ProductName, result.GetErrorAsString("ChiDinhBus.InsertChiDinh"), IconType.Error);
                                    Utility.WriteToTraceLog(result.GetErrorAsString("ChiDinhBus.InsertChiDinh"));
                                    this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                                }
                                else
                                {
                                    DichVuChiDinh dichVuChiDinh = new DichVuChiDinh();
                                    dichVuChiDinh.ServiceHistoryGUID = _serviceHistory.ServiceHistoryGUID;
                                    dichVuChiDinh.ChiTietChiDinhGUID = ctcd.ChiTietChiDinhGUID;
                                    dichVuChiDinh.CreatedDate = DateTime.Now;
                                    dichVuChiDinh.CraetedBy = Guid.Parse(Global.UserGUID);
                                    dichVuChiDinh.Status = (byte)Status.Actived;

                                    result = ChiDinhBus.InsertDichVuChiDinh(dichVuChiDinh);
                                    if (!result.IsOK)
                                    {
                                        MsgBox.Show(Application.ProductName, result.GetErrorAsString("ChiDinhBus.InsertDichVuChiDinh"), IconType.Error);
                                        Utility.WriteToTraceLog(result.GetErrorAsString("ChiDinhBus.InsertDichVuChiDinh"));
                                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                                    }
                                }
                            }
                            else
                            {
                                _chiDinh.UpdatedDate = DateTime.Now;
                                _chiDinh.UpdatedBy = Guid.Parse(Global.UserGUID);
                                _chiDinh.Status = (byte)Status.Actived;

                                _chiDinh.BacSiChiDinhGUID = Guid.Parse(cboBacSiChiDinh.SelectedValue.ToString());
                                result = ChiDinhBus.UpdateChiDinh(_chiDinh, cboService.SelectedValue.ToString());
                                if (!result.IsOK)
                                {
                                    MsgBox.Show(Application.ProductName, result.GetErrorAsString("ChiDinhBus.UpdateChiDinh"), IconType.Error);
                                    Utility.WriteToTraceLog(result.GetErrorAsString("ChiDinhBus.UpdateChiDinh"));
                                    this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                                }
                            }
                        }
                        else if (_chiDinh != null)
                        {
                            List<string> keys = new List<string>();
                            keys.Add(_chiDinh.ChiDinhGUID.ToString());
                            result = ChiDinhBus.DeleteChiDinhs(keys);
                            if (!result.IsOK)
                            {
                                MsgBox.Show(Application.ProductName, result.GetErrorAsString("ChiDinhBus.DeleteChiDinhs"), IconType.Error);
                                Utility.WriteToTraceLog(result.GetErrorAsString("ChiDinhBus.DeleteChiDinhs"));
                                this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                            }
                        }
                    }
                };

                if (InvokeRequired) BeginInvoke(method);
                else method.Invoke();
            }
            catch (Exception e)
            {
                MsgBox.Show(this.Text, e.Message, IconType.Error);
                Utility.WriteToTraceLog(e.Message);
            }
        }