protected void frmvwAddUpdatePatient_ItemCommand(object sender, FormViewCommandEventArgs e)
        {
            TextBox         txtPatientName = (TextBox)frmvwAddUpdatePatient.FindControl("txtPatientName");
            TextBox         txtAge         = (TextBox)frmvwAddUpdatePatient.FindControl("txtAge");
            TextBox         txtOccupation  = (TextBox)frmvwAddUpdatePatient.FindControl("txtOccupation");
            TextBox         txtMobileNo    = (TextBox)frmvwAddUpdatePatient.FindControl("txtMobileNo");
            RadioButtonList rdbtnlstGender = (RadioButtonList)frmvwAddUpdatePatient.FindControl("rdbtnlstGender");
            HtmlTextArea    txtAddress     = (HtmlTextArea)frmvwAddUpdatePatient.FindControl("txtAddress");

            if (e.CommandName == "AddPatient")
            {
                DC_Message        _msg    = new DC_Message();
                DC_PatientDetails _objAdd = new DC_PatientDetails();
                _objAdd.Name       = txtPatientName.Text;
                _objAdd.Age        = Convert.ToInt32(txtAge.Text);
                _objAdd.Occupation = txtOccupation.Text;
                _objAdd.Mobile     = txtMobileNo.Text;
                _objAdd.Address    = txtAddress.Value;
                _objAdd.Gender     = rdbtnlstGender.SelectedItem.Text;
                _objAdd.CreatedBy  = "Ajay";
                _msg = _objDL.AddUpdatePatientDetails(_objAdd);
                if (_msg.StatusCode == ReadOnlyMessage.StatusCode.Success)
                {
                    BootstrapAlert.BootstrapAlertMessage(divmsg, _msg.StatusMessage, BootstrapAlertType.Success);
                    hdnFlag.Value = "true";
                }
            }
            if (e.CommandName == "EditPatient")
            {
                DC_Message        _msg    = new DC_Message();
                DC_PatientDetails _objAdd = new DC_PatientDetails();
                _objAdd.ID         = Guid.Parse(Convert.ToString(frmvwAddUpdatePatient.DataKey.Value));
                _objAdd.Name       = txtPatientName.Text;
                _objAdd.Age        = Convert.ToInt32(txtAge.Text);
                _objAdd.Occupation = txtOccupation.Text;
                _objAdd.Mobile     = txtMobileNo.Text;
                _objAdd.Address    = "Goregoan";
                _objAdd.Gender     = rdbtnlstGender.SelectedItem.Text;
                _objAdd.EditedBy   = "Ajay";
                _msg = _objDL.AddUpdatePatientDetails(_objAdd);
                if (_msg.StatusCode == ReadOnlyMessage.StatusCode.Success)
                {
                    BootstrapAlert.BootstrapAlertMessage(divmsg, _msg.StatusMessage, BootstrapAlertType.Success);
                    hdnFlag.Value = "true";
                }
            }
        }
예제 #2
0
        public DC_Message AddUpdatePatientDetails(DC_PatientDetails _objSave)
        {
            DC_Message _msg = new DC_Message();

            try
            {
                using (CLMS_DBEntities context = new CLMS_DBEntities())
                {
                    if (_objSave.ID != null && _objSave.ID != Guid.Empty) //Edit
                    {
                        var isduplicate = (from p in context.tbl_PatientDetails
                                           where p.ID != _objSave.ID && p.Name == _objSave.Name && p.Mobile == _objSave.Mobile
                                           select p).Count() == 0 ? false : true;

                        if (isduplicate)
                        {
                            _msg.StatusMessage = strClassFor + ReadOnlyMessage.strAlreadyExist;
                            _msg.StatusCode    = ReadOnlyMessage.StatusCode.Duplicate;
                            return(_msg);
                        }
                        var patient = context.tbl_PatientDetails.Find(_objSave.ID);
                        if (patient != null)
                        {
                            patient.Name       = _objSave.Name;
                            patient.Mobile     = _objSave.Mobile;
                            patient.Age        = _objSave.Age;
                            patient.Address    = _objSave.Address;
                            patient.Occupation = _objSave.Occupation;
                            patient.Gender     = _objSave.Gender;
                            patient.EditedBy   = _objSave.EditedBy;
                            patient.EditedDate = DateTime.Now;
                            patient.IsActive   = _objSave.IsActive;
                            if (context.SaveChanges() == 1)
                            {
                                _msg.StatusMessage = strClassFor + ReadOnlyMessage.strUpdatedSuccessfully;
                                _msg.StatusCode    = ReadOnlyMessage.StatusCode.Success;
                            }
                            else
                            {
                                _msg.StatusMessage = strClassFor + ReadOnlyMessage.strFailed;
                                _msg.StatusCode    = ReadOnlyMessage.StatusCode.Failed;
                            }
                        }
                        else
                        {
                        }
                    }
                    else //Add
                    {
                        var isduplicate = (from p in context.tbl_PatientDetails
                                           where p.Name == _objSave.Name && p.Mobile == _objSave.Mobile
                                           select p).Count() == 0 ? false : true;

                        if (isduplicate)
                        {
                            _msg.StatusMessage = strClassFor + ReadOnlyMessage.strAlreadyExist;
                            _msg.StatusCode    = ReadOnlyMessage.StatusCode.Duplicate;
                            return(_msg);
                        }

                        tbl_PatientDetails _objP = new tbl_PatientDetails
                        {
                            ID          = Guid.NewGuid(),
                            Name        = _objSave.Name,
                            Mobile      = _objSave.Mobile,
                            Age         = _objSave.Age,
                            Occupation  = _objSave.Occupation,
                            Address     = _objSave.Address,
                            Gender      = _objSave.Gender,
                            CreatedBy   = _objSave.CreatedBy,
                            CreatedDate = DateTime.Now,
                            IsActive    = _objSave.IsActive,
                        };
                        context.tbl_PatientDetails.Add(_objP);
                        if (context.SaveChanges() == 1)
                        {
                            _msg.StatusMessage = strClassFor + ReadOnlyMessage.strAddedSuccessfully;
                            _msg.StatusCode    = ReadOnlyMessage.StatusCode.Success;
                        }
                        else
                        {
                            _msg.StatusMessage = strClassFor + ReadOnlyMessage.strFailed;
                            _msg.StatusCode    = ReadOnlyMessage.StatusCode.Failed;
                        }
                    }
                }
            }
            catch (Exception)
            {
                _msg.StatusMessage = ReadOnlyMessage.strFailed;
                _msg.StatusCode    = ReadOnlyMessage.StatusCode.Failed;
            }
            return(_msg);
        }