Ejemplo n.º 1
0
        //Imprort Contact
        public void ImportContact(DataGridView gr)
        {
            try
            {
                flagErr = true;
                errBuilder = new StringBuilder();
                ContactPatient ObjContactPatient = new ContactPatient();
                foreach (DataGridViewRow row in gr.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        ObjContactPatient.Ivg_patientnumber = row.Cells[0].Value.ToString();
                        ObjContactPatient.Fullname = row.Cells[1].Value.ToString();
                        ObjContactPatient.Birthdate = Convert.ToDateTime(row.Cells[2].Value.ToString());
                        ObjContactPatient.Ivg_age = row.Cells[3].Value.ToString();
                        ObjContactPatient.Gendercode = row.Cells[4].Value.ToString();
                        ObjContactPatient.Familystatuscode = row.Cells[5].Value.ToString();
                        ObjContactPatient.Ivg_address = row.Cells[6].Value.ToString();
                        ObjContactPatient.Ivg_provinceid = row.Cells[7].Value.ToString();
                        ObjContactPatient.Ivg_nationalityid = row.Cells[8].Value.ToString();
                        ObjContactPatient.Ivg_officeaddress = row.Cells[9].Value.ToString();
                        ObjContactPatient.Address1_telephone2 = row.Cells[10].Value.ToString();
                        ObjContactPatient.Mobilephone = row.Cells[11].Value.ToString();
                        ObjContactPatient.Telephone1 = row.Cells[12].Value.ToString();
                        //
                        ObjContactPatient.Emailaddress1 = row.Cells[13].Value.ToString();
                        ObjContactPatient.Description = row.Cells[14].Value.ToString();

                        Result result = DAOProcessContactPatient.Create(ObjContactPatient);
                        if (result.isError)
                        {
                            flagErr = false;
                            LogError.log.Error(result.BusinessObject.ToString());
                            errBuilder.Append(result.BusinessObject.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError.log.Error(ex.StackTrace);
            }
        }
        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);
            }
        }