Exemplo n.º 1
0
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            if (context.MessageName.ToLower() != "create") return;

            if (!context.InputParameters.Contains("Target") && !(context.InputParameters["Target"] is Entity)) return;

            Entity entity = (Entity)context.InputParameters["Target"];

            if (entity.LogicalName != "ivg_specialty") return;

            if (!entity.Contains("ivg_code")) return;

            if (!entity.Contains("ivg_id")) return;

            #region Process
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            bool fError = false;
            try
            {
                //checked TRUNG
                if (entity.Contains("ivg_code") || entity.Contains("ivg_id"))
                {
                    var ivg_code = entity.Attributes["ivg_code"].ToString();
                    var ivg_id = entity.Attributes["ivg_id"].ToString();
                    string [] values = { ivg_code.ToString(), ivg_id.ToString() };
                    CheckDuplicate objcheck = new CheckDuplicate();
                    string[] columName = { "ivg_code", "ivg_id" };
                    string[] attName = { "ivg_code", "ivg_id" };
                   // if (objcheck.CheckDuplicateMuti(service, entity.LogicalName, attName, values, columName))
                    if (objcheck.CheckDuplicateBase(service, entity.LogicalName, attName, values, columName))
                    {
                        fError = true;
                        throw new InvalidPluginExecutionException("Trung CODEID hoac ID number!");
                    }
                }
            }

            catch (Exception ex)
            {
                if (fError)
                    throw new InvalidPluginExecutionException("Trung codeID number kiem tra lai!");
                else
                    throw new Exception("Lỗi xảy ra:" + " " + ex.StackTrace);
            }
            #endregion
        }
Exemplo n.º 2
0
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            if (context.MessageName.ToLower() != "create") return;

            if (!context.InputParameters.Contains("Target") && !(context.InputParameters["Target"] is Entity)) return;

            Entity entity = (Entity)context.InputParameters["Target"];

            if (entity.LogicalName != "ivg_clinicroom") return;

            if (!entity.Contains("ivg_code")) return;

            #region Process
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            bool fError = false;
            string strERR = string.Empty;
            try
            {
                //checked TRUNG
                if (entity.Contains("ivg_code"))
                {
                   // var ivg_code = entity.Attributes["ivg_code"].ToString();
                    string[] values = { entity.Attributes["ivg_code"].ToString() };
                    CheckDuplicate objcheck = new CheckDuplicate();
                    string[] columName = { "ivg_code" };
                    if (objcheck.CheckDuplicateBase (service, entity.LogicalName, columName, values, columName))
                    {
                        fError = true;
                        strERR = objcheck.FlagErr.ToString();
                        throw new InvalidPluginExecutionException("Trùng Code Id vui lòng kiểm tra lại!");
                    }
                }
            }

            catch (Exception ex)
            {
                if (fError)
                    throw new InvalidPluginExecutionException("Trùng Code Id vui lòng kiểm tra lại!");
                else
                    throw new Exception("Lỗi xảy ra:" + " " + ex.StackTrace);
            }
            #endregion
        }
Exemplo n.º 3
0
        public Result Create(ItemType ObjItemType)
        {
            try
            {
                if (service == null)
                {
                    LogError.log.Error("Service is null");
                    throw new Exception("Service is null");
                }
                Entity objEntity = new Entity("ivg_itemtype");
                objEntity.Attributes["ivg_id"] = ObjItemType.Ivg_id;
                objEntity.Attributes["ivg_name"] = ObjItemType.Ivg_name;

                CheckDuplicate objcheck = new CheckDuplicate();
                string[] columName = { "ivg_id" };
                string[] att = { "ivg_id" };
                string[] values = { objEntity.Attributes["ivg_id"].ToString() };

                 if (objcheck.CheckDuplicateBase(service, objEntity.LogicalName, att, values, columName))
                //if (CheckDuplicateID(service, "ivg_itemtype", "ivg_id", ObjItemType.Ivg_id, "ivg_id"))
                {
                    //Update Name neu ID trung
                    //objEntity.Attributes["ivg_id"] = ObjItemType.Ivg_id;
                    ColumnSet attributes = new ColumnSet(new string[] { "ivg_id", "ivg_name" });
                    GuidTemp = objcheck.IdGui;
                    objEntity = service.Retrieve(objEntity.LogicalName, GuidTemp, attributes);
                    objEntity.Attributes["ivg_name"] = ObjItemType.Ivg_name;
                    service.Update(objEntity);

                    //End Update
                    return new Result("", true, ObjItemType.Ivg_id);
                }
                else
                {
                    Guid EntityID = service.Create(objEntity);
                    return new Result("", false, EntityID);
                }
            }
            catch (Exception ex)
            {
                LogError.log.Error(ex.StackTrace);
                return new Result(ex.StackTrace, true);
            }
        }
        public static Result Create(ContactPatient ObjContactPatient)
        {
            try
            {
                Connect();

                if (service == null)
                {
                    LogError.log.Error("Service is null");
                    throw new Exception("Service is null");
                }
                string gendercode, Familystatus;
                Entity objEntity = new Entity("contact");
                objEntity.Attributes["ivg_patientnumber"] = ObjContactPatient.Ivg_patientnumber;
                objEntity.Attributes["lastname"] = ObjContactPatient.Fullname;
                objEntity.Attributes["birthdate"] = ObjContactPatient.Birthdate;
                gendercode = ObjContactPatient.Gendercode == "MALE" ? "1" : "2";
                objEntity.Attributes.Add("gendercode", new OptionSetValue(int.Parse(gendercode)));
                objEntity.Attributes["ivg_age"] = ObjContactPatient.Ivg_age;

                if (ObjContactPatient.Familystatuscode == "SINGLE")
                {
                    Familystatus = "1";
                }
                else if (ObjContactPatient.Familystatuscode == "MARRIED")
                {
                    Familystatus = "2";
                }
                else if (ObjContactPatient.Familystatuscode == "DIVORCED")
                {
                    Familystatus = "3";
                }
                else
                {
                    Familystatus = "4";
                }
                objEntity.Attributes.Add("familystatuscode", new OptionSetValue(int.Parse(Familystatus)));
                if (!(CountryOld == ObjContactPatient.Ivg_nationalityid))
                {
                    //lay ve Entity ivg_country
                    QueryExpression query = new QueryExpression("ivg_country");
                    query.Criteria.AddCondition("ivg_name", ConditionOperator.Equal, ObjContactPatient.Ivg_nationalityid);
                    string[] str = { "ivg_name", "ivg_countryid" };
                    query.ColumnSet = new ColumnSet(str);
                    EntityCollection entityes = service.RetrieveMultiple(query);
                    Typecountry = entityes.Entities[0];
                    objEntity.Attributes["ivg_nationalityid"] = new EntityReference("ivg_country", Typecountry.Id);
                    CountryOld = ObjContactPatient.Ivg_nationalityid;
                    GuidCountryOld = Typecountry.Id;
                }
                else
                {
                    objEntity.Attributes["ivg_nationalityid"] = new EntityReference("ivg_country", GuidCountryOld);
                }
                //--------------------------------------------

                objEntity.Attributes["ivg_address"] = ObjContactPatient.Ivg_address;
                if (!(ProvinceOld == ObjContactPatient.Ivg_provinceid))
                {
                    //lay ve Entity ivg_province
                    QueryExpression query_province = new QueryExpression("ivg_province");
                    query_province.Criteria.AddCondition("ivg_name", ConditionOperator.Equal, ObjContactPatient.Ivg_provinceid);
                    string[] str2 = { "ivg_name", "ivg_provinceid" };
                    query_province.ColumnSet = new ColumnSet(str2);
                    EntityCollection entityes2 = service.RetrieveMultiple(query_province);
                    Typeprovince = entityes2.Entities[0];
                    objEntity.Attributes["ivg_provinceid"] = new EntityReference("ivg_province", Typeprovince.Id);
                    ProvinceOld = ObjContactPatient.Ivg_provinceid;
                    GuidProvinceOld = Typeprovince.Id;
                }
                else
                {
                    objEntity.Attributes["ivg_provinceid"] = new EntityReference("ivg_province", GuidProvinceOld);
                }
                //--------------------------------------------
                objEntity.Attributes["emailaddress1"] = ObjContactPatient.Emailaddress1;
                objEntity.Attributes["address1_telephone2"] = ObjContactPatient.Address1_telephone2;
                objEntity.Attributes["description"] = ObjContactPatient.Description;

                CheckDuplicate objcheck = new CheckDuplicate();
                string[] columName = { "ivg_patientnumber" };
                string[] att = { "ivg_patientnumber" };
                string[] values = { objEntity.Attributes["ivg_patientnumber"].ToString() };

                    if (objcheck.CheckDuplicateBase(service, objEntity.LogicalName, att, values, columName))
                    {
                        ColumnSet attributes = new ColumnSet(new string[] { "ivg_patientnumber" });
                        GuidTemp = objcheck.IdGui;
                        objEntity = service.Retrieve(objEntity.LogicalName, GuidTemp, attributes);
                        //objEntity.Attributes["ivg_familyrelationship"] = ObjContactPatient.Ivg_familyrelationship;
                        objEntity.Attributes["birthdate"] = ObjContactPatient.Birthdate;
                        objEntity.Attributes.Add("gendercode", new OptionSetValue(int.Parse(gendercode)));
                        objEntity.Attributes["ivg_age"] = ObjContactPatient.Ivg_age;
                        objEntity.Attributes.Add("familystatuscode", new OptionSetValue(int.Parse(Familystatus)));
                        objEntity.Attributes["ivg_nationalityid"] = new EntityReference("ivg_country", Typecountry.Id);
                        objEntity.Attributes["ivg_address"] = ObjContactPatient.Ivg_address;
                        objEntity.Attributes["ivg_provinceid"] = new EntityReference("ivg_province", Typeprovince.Id);
                        objEntity.Attributes["emailaddress1"] = ObjContactPatient.Emailaddress1;
                        objEntity.Attributes["address1_telephone2"] = ObjContactPatient.Address1_telephone2;
                        objEntity.Attributes["description"] = ObjContactPatient.Description;
                        service.Update(objEntity);

                        return new Result("", true, ObjContactPatient.Ivg_patientnumber);
                    }
                    else
                    {
                        Guid EntityID = service.Create(objEntity);
                        return new Result("", false, EntityID);
                    }

            }
            catch (Exception ex)
            {
                LogError.log.Error(ex.StackTrace);
                return new Result(ex.StackTrace, true);
            }
        }