//String query1 = "Select Ad_User_id from Ad_user where C_bpartner_id=1001864";
        //int AD_Id = Util.GetValueOfInt(DB.ExecuteScalar(query1));
        //X_AD_User user = new X_AD_User(GetCtx(), AD_Id, null);
        //return "";



        // query = "Select C_TargetList_id from C_TargetList where C_TargetList_id not in (Select C_TargetList_id from C_InviteeList) and c_campaign_id="+Record_ID;
        //IDataReader dr = DB.ExecuteReader(query);
        //while (dr.Read())
        //{
        //     X_C_TargetList TList = new X_C_TargetList(GetCtx(), Util.GetValueOfInt(dr[0]), Get_Trx());

        //     if (TList.GetC_BPartner_ID()!=0)
        //     {
        //         invitee(Util.GetValueOfInt(dr[0]));



        //     }

        //     if (TList.GetRef_BPartner_ID() !=0)
        //     {
        //         invitee( Util.GetValueOfInt(dr[0]));
        //     }
        //     if (TList.GetC_Lead_ID() != 0)
        //     {
        //         X_C_Lead lead = new X_C_Lead(GetCtx(), TList.GetC_Lead_ID(), Get_Trx());
        //         if (lead.GetC_BPartner_ID() != 0)
        //         {
        //             invitee(lead.GetC_BPartner_ID());
        //         }
        //         else if (lead.GetRef_BPartner_ID() !=0)
        //         {
        //             invitee( Util.GetValueOfInt(dr[0]));
        //         }
        //         else if (lead.GetContactName() !=null)
        //         {
        //             X_C_InviteeList Invt = new X_C_InviteeList(GetCtx(), 0, Get_Trx());
        //             Invt.SetC_TargetList_ID(Util.GetValueOfInt(dr[0]));
        //             Invt.SetName(lead.GetContactName());
        //             Invt.SetEMail(lead.GetEMail());
        //             Invt.SetPhone(lead.GetPhone());
        //             Invt.SetC_Lead_ID(lead.GetC_Lead_ID());
        //             if (!Invt.Save())
        //             {
        //             }
        //         }
        //     }
        //}
        //return "";

        public void invitee(int bpid)
        {
            VAdvantage.Model.X_C_BPartner bp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bpid, Get_Trx());
            String query = "Select Ad_User_id from Ad_user where C_bpartner_id=" + bpid;
            int    AD_Id = Util.GetValueOfInt(DB.ExecuteScalar(query, null, Get_Trx()));
            string sql   = "Select C_InviteeList_id from C_InviteeList where Ad_User_id=" + AD_Id + " and C_Campaign_id=" + GetRecord_ID();
            object id    = DB.ExecuteScalar(sql, null, Get_Trx());

            VAdvantage.Model.X_C_InviteeList Invt;
            if (Util.GetValueOfInt(id) != 0)
            {
                Invt = new VAdvantage.Model.X_C_InviteeList(GetCtx(), Util.GetValueOfInt(id), Get_Trx());
            }
            else
            {
                Invt = new VAdvantage.Model.X_C_InviteeList(GetCtx(), 0, Get_Trx());
                Invt.SetAD_User_ID(AD_Id);
            }
            VAdvantage.Model.X_AD_User user = new VAdvantage.Model.X_AD_User(GetCtx(), AD_Id, Get_Trx());
            int BpLoc = user.GetC_BPartner_Location_ID();

            if (BpLoc != 0)
            {
                String Sql = "Select C_Location_ID From C_Bpartner_location where C_Bpartner_location_id=" + BpLoc;
                Invt.SetC_Location_ID(Util.GetValueOfInt(DB.ExecuteScalar(Sql)));
            }
            Invt.SetC_Campaign_ID(GetRecord_ID());
            Invt.SetName(user.GetName());
            Invt.SetEMail(user.GetEMail());
            Invt.SetPhone(user.GetPhone());
            // Invt.SetURL(url);
            if (!Invt.Save(Get_Trx()))
            {
                Msg.GetMsg(GetCtx(), "InviteeCteationNotDone");
            }

            string ID       = Invt.GetC_InviteeList_ID().ToString();
            string encrypt  = FormsAuthentication.HashPasswordForStoringInConfigFile(ID, "SHA1");
            string urlFinal = "";

            urlFinal = url + "?" + encrypt;
            sql      = "update c_inviteelist set url = '" + urlFinal + "' where c_inviteelist_id = " + Invt.GetC_InviteeList_ID();
            int res = Util.GetValueOfInt(DB.ExecuteQuery(sql, null, Get_Trx()));


            //Random rand = new Random();
            //String s = "";
            //for (int i = 0; i < 9; i++)
            //    s = String.Concat(s, rand.Next(10).ToString());
            //string urlFinal = "";
            ////// urlFinal = url + "?" + Invt.GetC_InviteeList_ID().ToString();
            //urlFinal = url + "?" + s;
            //sql = "update c_inviteelist set url = '" + urlFinal + "' where c_inviteelist_id = " + Invt.GetC_InviteeList_ID();
            //int res = Util.GetValueOfInt(DB.ExecuteQuery(sql, null, Get_Trx()));
            //Invt.SetURL(urlFinal);
            //if (!Invt.Save(Get_Trx()))
            //{
            //    Msg.GetMsg(GetCtx(), "InviteeCteationNotDone");
            //}
        }
Esempio n. 2
0
        protected override String DoIt()
        {
            VAdvantage.Model.X_C_Lead lead = new VAdvantage.Model.X_C_Lead(GetCtx(), _C_Lead_ID, Get_Trx());
            if (!(R_InterestArea_ID > 0))
            {
                return(Msg.GetMsg(GetCtx(), "NoInterestAreaIsSelected"));
            }

            if (lead.GetC_BPartner_ID() != 0)
            {
                VAdvantage.Model.X_R_ContactInterest customer = new VAdvantage.Model.X_R_ContactInterest(GetCtx(), 0, Get_Trx());
                customer.SetR_InterestArea_ID(R_InterestArea_ID);
                customer.SetC_BPartner_ID(lead.GetC_BPartner_ID());
                String query  = "Select ad_user_id from ad_user where c_bpartner_id= " + lead.GetC_BPartner_ID();
                int    UserId = Util.GetValueOfInt(DB.ExecuteScalar(query));
                customer.SetAD_User_ID(UserId);
                query = "Select C_BPartner_Location_id from C_BPartner_Location where c_bpartner_id= " + lead.GetC_BPartner_ID();

                int Id = Util.GetValueOfInt(DB.ExecuteScalar(query));
                VAdvantage.Model.X_C_BPartner_Location loc = new VAdvantage.Model.X_C_BPartner_Location(GetCtx(), Id, Get_Trx());
                customer.SetC_BPartner_Location_ID(Id);
                customer.SetPhone(loc.GetPhone());
                customer.SetFax(loc.GetFax());

                VAdvantage.Model.X_AD_User us = new VAdvantage.Model.X_AD_User(GetCtx(), UserId, Get_Trx());
                customer.SetC_Job_ID(us.GetC_Job_ID());
                customer.SetSubscribeDate(DateTime.Today);
                query = "Select Email from ad_user where ad_user_id= " + UserId;
                String mail = Util.GetValueOfString(DB.ExecuteScalar(query));
                customer.SetEMail(mail);
                if (!customer.Save())
                {
                    return(Msg.GetMsg(GetCtx(), "NotSubscribed"));
                }
                lead.SetR_InterestArea_ID(customer.GetR_InterestArea_ID());
                if (lead.Save())
                {
                }
                return(Msg.GetMsg(GetCtx(), "SubscribedDone"));
            }
            else if (lead.GetRef_BPartner_ID() != 0)
            {
                VAdvantage.Model.X_R_ContactInterest Prospect = new VAdvantage.Model.X_R_ContactInterest(GetCtx(), 0, Get_Trx());
                Prospect.SetR_InterestArea_ID(R_InterestArea_ID);
                Prospect.SetC_BPartner_ID(lead.GetRef_BPartner_ID());
                String query  = "Select ad_user_id from ad_user where c_bpartner_id= " + lead.GetRef_BPartner_ID();
                int    UserId = Util.GetValueOfInt(DB.ExecuteScalar(query));
                Prospect.SetAD_User_ID(UserId);
                query = "Select C_BPartner_Location_id from C_BPartner_Location where c_bpartner_id= " + lead.GetRef_BPartner_ID();

                int Id = Util.GetValueOfInt(DB.ExecuteScalar(query));
                VAdvantage.Model.X_C_BPartner_Location loc = new VAdvantage.Model.X_C_BPartner_Location(GetCtx(), Id, Get_Trx());
                Prospect.SetC_BPartner_Location_ID(Id);
                Prospect.SetPhone(loc.GetPhone());
                Prospect.SetFax(loc.GetFax());

                VAdvantage.Model.X_AD_User us = new VAdvantage.Model.X_AD_User(GetCtx(), UserId, Get_Trx());
                Prospect.SetC_Job_ID(us.GetC_Job_ID());
                Prospect.SetSubscribeDate(DateTime.Today);
                query = "Select Email from ad_user where ad_user_id= " + UserId;
                String mail = Util.GetValueOfString(DB.ExecuteScalar(query));
                Prospect.SetEMail(mail);
                if (!Prospect.Save())
                {
                    return(Msg.GetMsg(GetCtx(), "NotSubscribed"));
                }
                lead.SetR_InterestArea_ID(Prospect.GetR_InterestArea_ID());
                if (lead.Save())
                {
                }
                return(Msg.GetMsg(GetCtx(), "SubscribedDone"));
            }
            else
            {
                VAdvantage.Model.X_vss_lead_interestarea Ilead = new VAdvantage.Model.X_vss_lead_interestarea(GetCtx(), 0, Get_Trx());
                Ilead.SetC_Lead_ID(lead.GetC_Lead_ID());
                Ilead.SetR_InterestArea_ID(R_InterestArea_ID);
                Ilead.SetAD_User_ID(lead.GetAD_User_ID());
                Ilead.SetBPName(lead.GetBPName());
                Ilead.SetEMail(lead.GetEMail());
                Ilead.SetPhone(lead.GetPhone());
                Ilead.SetFax(lead.GetFax());
                Ilead.SetAddress1(lead.GetAddress1());
                Ilead.SetAddress2(lead.GetAddress2());
                Ilead.SetC_City_ID(lead.GetC_City_ID());
                Ilead.SetCity(lead.GetCity());
                Ilead.SetC_Region_ID(lead.GetC_Region_ID());
                Ilead.SetRegionName(lead.GetRegionName());
                Ilead.SetC_Country_ID(lead.GetC_Country_ID());
                Ilead.SetPostal(lead.GetPostal());
                Ilead.SetSubscribeDate(DateTime.Today);
                if (!Ilead.Save())
                {
                    return(Msg.GetMsg(GetCtx(), "NotSubscribed"));
                }
                lead.SetR_InterestArea_ID(Ilead.GetR_InterestArea_ID());
                if (lead.Save())
                {
                }
                return(Msg.GetMsg(GetCtx(), "SubscribedDone"));
            }
        }
Esempio n. 3
0
        protected override String DoIt()
        {
            if (S_Resource_id == 0)
            {
                throw new ArgumentException("C_Project_ID == 0");
            }
            VAdvantage.Model.MResource Resource = new VAdvantage.Model.MResource(GetCtx(), S_Resource_id, Get_Trx());
            string sql         = "select ProfileType from s_resource where s_resource_id=" + S_Resource_id + "";
            string ProfileType = VAdvantage.Utility.Util.GetValueOfString(DB.ExecuteScalar(sql));

            VAdvantage.Model.X_AD_User user = new VAdvantage.Model.X_AD_User(GetCtx(), 0, Get_Trx());
            VAdvantage.Model.MBPartner bp   = new VAdvantage.Model.MBPartner(GetCtx(), C_Bpartner_ID, Get_Trx());
            if (ProfileType == "")
            {
                return(Msg.GetMsg(GetCtx(), "ProfileTypeNotSelected"));
            }
            else
            {
                if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BP_Group_ID()) == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "ResourceNotSelected"));
                }

                if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_Role_ID()) == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "RoleNotSelected"));
                }
                if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_Location_ID()) == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "AddressNotSelected"));
                }
                if (ProfileType == "I")
                {
                    if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BPartner_ID()) == 0 && VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_User_ID()) == 0)
                    {
                        sql = "select count(*) from c_bpartner where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            bp.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            bp.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            bp.SetIsEmployee(true);
                            bp.SetName(Resource.GetName());
                            bp.SetEMail(Resource.GetEMail());
                            bp.SetMobile(Resource.GetMobile());
                            bp.SetC_Location_ID(Resource.GetC_Location_ID());
                            bp.SetC_BP_Group_ID(Resource.GetC_BP_Group_ID());
                            if (!bp.Save())
                            {
                                log.SaveError("BusinessPartnerNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "BusinessPartnerNotSaved"));
                            }

                            VAdvantage.Model.MBPartnerLocation bploc = new VAdvantage.Model.MBPartnerLocation(GetCtx(), 0, Get_Trx());
                            bploc.SetAD_Client_ID(bp.GetAD_Client_ID());
                            bploc.SetAD_Org_ID(bp.GetAD_Org_ID());
                            bploc.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                            bploc.SetPhone(Resource.GetMobile());
                            bploc.SetC_Location_ID(Resource.GetC_Location_ID());

                            if (!bploc.Save())
                            {
                                log.SaveError("BusinessPartnerLocationNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "BusinessPartnerLocationNotSaved,"));
                            }
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "BPNotSaved," + Resource.GetName() + "AlreadyExists!"));
                        }

                        sql = "select count(*) from ad_user where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            user.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            user.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            user.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                            user.SetEMail(Resource.GetEMail());
                            user.SetName(Resource.GetName());
                            user.SetPhone(Resource.GetMobile());
                            user.SetC_Location_ID(Resource.GetC_Location_ID());
                            user.SetIsLoginUser(true);
                            if (!user.Save())
                            {
                                log.SaveError("UserNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserNotSaved"));
                            }
                            string usrname  = user.GetName();
                            string Password = GenratePassword(usrname);
                            user.SetPassword(Password);
                            if (!user.Save())
                            {
                                log.SaveError("PasswordNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "PasswordNotSaved"));
                            }
                            int ad_role_id = Resource.GetAD_Role_ID();
                            VAdvantage.Model.X_AD_User_Roles userrole = new VAdvantage.Model.X_AD_User_Roles(GetCtx(), 0, Get_Trx());
                            userrole.SetAD_Role_ID(ad_role_id);
                            userrole.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            userrole.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            userrole.SetAD_User_ID(user.GetAD_User_ID());

                            if (!userrole.Save())
                            {
                                log.SaveError("UserRoleNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserRoleNotSaved"));
                            }

                            Resource.SetActivateForAssignment("Y");
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "UserNotSaved" + Resource.GetName() + "AlreadyExists"));
                        }
                    }
                    else if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BPartner_ID()) != 0 && VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_User_ID()) == 0)
                    {
                        sql = "select count(*) from ad_user where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            user.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            user.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            user.SetC_BPartner_ID(Resource.GetC_BPartner_ID());
                            user.SetEMail(Resource.GetEMail());
                            user.SetName(Resource.GetName());
                            user.SetPhone(Resource.GetMobile());
                            user.SetC_Location_ID(Resource.GetC_Location_ID());
                            user.SetIsLoginUser(true);
                            if (!user.Save())
                            {
                                log.SaveError("UserNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserNotSaved"));
                            }
                            //string sqlusr = "******" + user.GetAD_User_ID() + "";
                            //string usrname = VAdvantage.Utility.Util.GetValueOfString(DB.ExecuteScalar(sqlusr));
                            //GenratePassword(usrname);
                            string usrname  = user.GetName();
                            string Password = GenratePassword(usrname);
                            user.SetPassword(Password);
                            if (!user.Save())
                            {
                                log.SaveError("PasswordNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "PasswordNotSaved"));
                            }

                            int ad_role_id = Resource.GetAD_Role_ID();
                            VAdvantage.Model.X_AD_User_Roles userrole = new VAdvantage.Model.X_AD_User_Roles(GetCtx(), 0, Get_Trx());
                            userrole.SetAD_Role_ID(ad_role_id);
                            userrole.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            userrole.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            userrole.SetAD_User_ID(user.GetAD_User_ID());

                            if (!userrole.Save())
                            {
                                log.SaveError("UserRoleNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserRoleNotSaved"));
                            }

                            Resource.SetActivateForAssignment("Y");
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "UserNotSaved" + Resource.GetName() + "AlreadyExists"));
                        }
                    }
                }
                else if (ProfileType == "E")
                {
                    if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BPartner_ID()) == 0 && VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_User_ID()) == 0)
                    {
                        sql = "select count(*) from c_bpartner where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            bp.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            bp.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            bp.SetIsVendor(true);
                            bp.SetName(Resource.GetName());
                            bp.SetEMail(Resource.GetEMail());
                            bp.SetMobile(Resource.GetMobile());
                            bp.SetC_Location_ID(Resource.GetC_Location_ID());
                            //if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BP_Group_ID()) == 0)
                            // {
                            //  return Msg.GetMsg(GetCtx(), "plzselectresource");
                            // }
                            // else
                            // {
                            bp.SetC_BP_Group_ID(Resource.GetC_BP_Group_ID());
                            // }
                            if (!bp.Save())
                            {
                                log.SaveError("BusinessPartnerNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "BusinessPartnerNotSaved"));
                            }

                            VAdvantage.Model.MBPartnerLocation bploc = new VAdvantage.Model.MBPartnerLocation(GetCtx(), 0, Get_Trx());
                            bploc.SetAD_Client_ID(bp.GetAD_Client_ID());
                            bploc.SetAD_Org_ID(bp.GetAD_Org_ID());
                            bploc.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                            bploc.SetPhone(Resource.GetMobile());

                            // if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_Location_ID()) == 0)
                            // {
                            //     return Msg.GetMsg(GetCtx(), "Plz enter Address");
                            // }
                            // else
                            //{
                            bploc.SetC_Location_ID(Resource.GetC_Location_ID());
                            //}

                            if (!bploc.Save())
                            {
                                log.SaveError("BusinessPartnerLocationNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "BusinessPartnerLocationNotSaved,"));
                            }
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "BPNotSaved," + Resource.GetName() + "AlreadyExists!"));
                        }

                        sql = "select count(*) from ad_user where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            user.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            user.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            user.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                            user.SetName(Resource.GetName());
                            user.SetEMail(Resource.GetEMail());
                            user.SetPhone(Resource.GetMobile());
                            user.SetC_Location_ID(Resource.GetC_Location_ID());
                            user.SetIsLoginUser(true);
                            if (!user.Save())
                            {
                                log.SaveError("UserNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserNotSaved"));
                            }
                            //string sqlusr = "******" + user.GetAD_User_ID() + "";
                            //string usrname = VAdvantage.Utility.Util.GetValueOfString(DB.ExecuteScalar(sqlusr));
                            string usrname  = user.GetName();
                            string Password = GenratePassword(usrname);
                            user.SetPassword(Password);
                            if (!user.Save())
                            {
                                log.SaveError("PasswordNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "PasswordNotSaved"));
                            }

                            int ad_role_id = Resource.GetAD_Role_ID();
                            VAdvantage.Model.X_AD_User_Roles userrole = new VAdvantage.Model.X_AD_User_Roles(GetCtx(), 0, Get_Trx());
                            userrole.SetAD_Role_ID(ad_role_id);
                            userrole.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            userrole.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            userrole.SetAD_User_ID(user.GetAD_User_ID());

                            if (!userrole.Save())
                            {
                                log.SaveError("UserRoleNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserRoleNotSaved"));
                            }

                            Resource.SetActivateForAssignment("Y");
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "UserNotSaved" + Resource.GetName() + "AlreadyExists"));
                        }
                    }
                    else if (VAdvantage.Utility.Util.GetValueOfInt(Resource.GetC_BPartner_ID()) != 0 && VAdvantage.Utility.Util.GetValueOfInt(Resource.GetAD_User_ID()) == 0)
                    {
                        sql = "select count(*) from ad_user where upper(name) = '" + Resource.GetName().ToUpper() + "'";
                        if (Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())) == 0)
                        {
                            user.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            user.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            user.SetC_BPartner_ID(Resource.GetC_BPartner_ID());
                            user.SetEMail(Resource.GetEMail());
                            user.SetName(Resource.GetName());
                            user.SetPhone(Resource.GetMobile());
                            user.SetC_Location_ID(Resource.GetC_Location_ID());
                            user.SetIsLoginUser(true);
                            if (!user.Save())
                            {
                                log.SaveError("UserNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserNotSaved"));
                            }
                            //string sqlusr = "******" + user.GetAD_User_ID() + "";
                            //string usrname = VAdvantage.Utility.Util.GetValueOfString(DB.ExecuteScalar(sqlusr));
                            string usrname  = user.GetName();
                            string Password = GenratePassword(usrname);
                            user.SetPassword(Password);
                            if (!user.Save())
                            {
                                log.SaveError("PasswordNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "PasswordNotSaved"));
                            }

                            int ad_role_id = Resource.GetAD_Role_ID();
                            VAdvantage.Model.X_AD_User_Roles userrole = new VAdvantage.Model.X_AD_User_Roles(GetCtx(), 0, Get_Trx());
                            userrole.SetAD_Role_ID(ad_role_id);
                            userrole.SetAD_Client_ID(Resource.GetAD_Client_ID());
                            userrole.SetAD_Org_ID(Resource.GetAD_Org_ID());
                            userrole.SetAD_User_ID(user.GetAD_User_ID());

                            if (!userrole.Save())
                            {
                                log.SaveError("UserRoleNotSaved", "");
                                return(Msg.GetMsg(GetCtx(), "UserRoleNotSaved"));
                            }

                            Resource.SetActivateForAssignment("Y");
                        }
                        else
                        {
                            return(Msg.GetMsg(GetCtx(), "UserNotSaved" + Resource.GetName() + "AlreadyExists"));
                        }
                    }
                }
            }
            if (bp != null)
            {
                if (Util.GetValueOfInt(bp.GetC_BPartner_ID()) != 0)
                {
                    Resource.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                }
            }
            if (user != null)
            {
                if (Util.GetValueOfInt(user.GetAD_User_ID()) != 0)
                {
                    Resource.SetAD_User_ID(user.GetAD_User_ID());
                }
            }
            if (!Resource.Save())
            {
                log.SaveError("ResourceNotSaved", "");
                return(Msg.GetMsg(GetCtx(), "ResourceNotSaved"));
            }



            return(Msg.GetMsg(GetCtx(), "ProcessCompleted"));
        }