Exemplo n.º 1
0
 public static object GetBusinessUnits(EvaluationContext context, params object[] parameters)
 {
     try
     {
         int userID = ValidationHelper.GetInteger(parameters[0], 0);
         var data   = CustomTableItemProvider.GetItems <UserBusinessUnitsItem>()
                      .WhereEquals("UserID", userID)
                      .Columns("BusinessUnitID")
                      .ToList();
         var buList = new List <string>();
         if (!DataHelper.DataSourceIsEmpty(data))
         {
             data.ForEach(x =>
             {
                 var unitName = CustomTableItemProvider.GetItem <BusinessUnitItem>(x.BusinessUnitID);
                 buList.Add(unitName?.GetStringValue("BusinessUnitName", string.Empty) ?? string.Empty);
             });
         }
         return(String.Join(",", buList));
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("Kadena Macro methods", "GetBusinessUnits", ex.Message);
         return(string.Empty);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Saves and updates the brand details
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (form.ValidateData())
     {
         if (QueryHelper.GetInteger("ItemID", 0) > 0)
         {
             var brandData = CustomTableItemProvider.GetItem <BrandItem>(QueryHelper.GetInteger("ItemID", 0));
             brandData.BrandCode = ValidationHelper.GetInteger(form.GetFieldValue("BrandCode"), 0);
             Response.Cookies["status"].Value    = QueryStringStatus.Updated;
             Response.Cookies["status"].HttpOnly = false;
             form.SaveData($"{CurrentDocument.Parent.AbsoluteURL}?status={QueryStringStatus.Updated}");
         }
         else
         {
             var brandData = new BrandItem();
             brandData.BrandCode                 = ValidationHelper.GetInteger(form.GetFieldValue("BrandCode"), 0);
             brandData.BrandName                 = ValidationHelper.GetString(form.GetFieldValue("BrandName"), string.Empty);
             brandData.BrandDescription          = ValidationHelper.GetString(form.GetFieldValue("BrandDescription"), string.Empty);
             brandData.Status                    = ValidationHelper.GetBoolean(form.GetFieldValue("Status"), true);
             Response.Cookies["status"].Value    = QueryStringStatus.Added;
             Response.Cookies["status"].HttpOnly = false;
             form.SaveData($"{CurrentDocument.Parent.AbsoluteURL}?status={QueryStringStatus.Added}");
         }
     }
     else
     {
         form.ShowValidationErrorMessage = true;
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentMaster.Title.TitleText = GetString("customtable.data.viewitemtitle");
        Page.Title = CurrentMaster.Title.TitleText;

        CurrentMaster.Title.TitleImage = GetImageUrl("CMSModules/CMS_CustomTables/viewitem.png");

        // Get custom table id from url
        int customTableId = QueryHelper.GetInteger("customtableid", 0);
        // Get custom table item id
        int itemId = QueryHelper.GetInteger("itemid", 0);

        DataClassInfo dci = DataClassInfoProvider.GetDataClass(customTableId);
        // Set edited object
        EditedObject = dci;

        if (dci != null)
        {
            // Check 'Read' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.customtables", "Read") &&
                !CMSContext.CurrentUser.IsAuthorizedPerClassName(dci.ClassName, "Read"))
            {
                RedirectToAccessDenied("cms.customtables", "Read");
            }

            CustomTableItemProvider ctProvider = new CustomTableItemProvider(CMSContext.CurrentUser);
            CustomTableItem item = ctProvider.GetItem(itemId, dci.ClassName);
            customTableViewItem.CustomTableItem = item;
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Gets the custom table item and moves it up. Called when the "Get and move item up" button is pressed.
    /// Expects the CreateCustomTableItem method to be run first.
    /// </summary>
    private bool GetAndMoveCustomTableItemUp()
    {
        string customTableClassName = "customtable.sampletable";

        // Check if Custom table 'Sample table' exists
        DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);

        if (customTable != null)
        {
            // Prepare the parameters
            string where = "ItemText LIKE N'New text'";
            int    topN    = 1;
            string columns = "ItemID";

            // Get the data set according to the parameters
            DataSet dataSet = CustomTableItemProvider.GetItems(customTableClassName, where, null, topN, columns);

            if (!DataHelper.DataSourceIsEmpty(dataSet))
            {
                // Get the custom table item ID
                int itemID = ValidationHelper.GetInteger(dataSet.Tables[0].Rows[0][0], 0);
                var item   = CustomTableItemProvider.GetItem(itemID, customTableClassName);

                // Move the item up
                item.Generalized.MoveObjectUp();

                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes the control properties.
 /// </summary>
 protected void SetupControl()
 {
     if (!this.StopProcessing)
     {
         BrandItem brandData = null;
         brandData = new BrandItem();
         form.AlternativeFormFullName = "KDA.Brand.KDA_Brand";
         form.Info = brandData;
         form.VisibilityFormName     = "KDA.Brand.KDA_Brand";
         form.SubmitButton.Visible   = false;
         btnCancel.Text              = ResHelper.GetString("Kadena.CreateBrand.Cancel");
         form.ValidationErrorMessage = ResHelper.GetString("Kadena.Brands.FormError");
         if (QueryHelper.GetInteger("ItemID", 0) > 0)
         {
             brandData    = CustomTableItemProvider.GetItem <BrandItem>(QueryHelper.GetInteger("ItemID", 0));
             form.Mode    = CMS.Base.Web.UI.FormModeEnum.Update;
             form.Info    = brandData;
             btnSave.Text = ResHelper.GetString("Kadena.CreateBrand.Update");
         }
         else
         {
             form.Mode    = CMS.Base.Web.UI.FormModeEnum.Insert;
             form.Info    = brandData;
             btnSave.Text = ResHelper.GetString("Kadena.CreateBrand.Save");
         }
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        PageTitle.TitleText = GetString("customtable.data.viewitemtitle");
        Page.Title          = PageTitle.TitleText;
        // Get custom table id from url
        int customTableId = QueryHelper.GetInteger("customtableid", 0);
        // Get custom table item id
        int itemId = QueryHelper.GetInteger("itemid", 0);

        DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(customTableId);

        // Set edited object
        EditedObject = dci;

        if (dci == null)
        {
            return;
        }

        // Check 'Read' permission
        if (!dci.CheckPermissions(PermissionsEnum.Read, SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser))
        {
            RedirectToAccessDenied("cms.customtables", "Read");
        }

        CustomTableItem item = CustomTableItemProvider.GetItem(itemId, dci.ClassName);

        customTableViewItem.CustomTableItem = item;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentMaster.Title.TitleText = GetString("customtable.data.viewitemtitle");
        Page.Title = CurrentMaster.Title.TitleText;

        CurrentMaster.Title.TitleImage = GetImageUrl("CMSModules/CMS_CustomTables/viewitem.png");

        // Get custom table id from url
        int customTableId = QueryHelper.GetInteger("customtableid", 0);
        // Get custom table item id
        int itemId = QueryHelper.GetInteger("itemid", 0);

        DataClassInfo dci = DataClassInfoProvider.GetDataClass(customTableId);

        // Set edited object
        EditedObject = dci;

        if (dci != null)
        {
            // Check 'Read' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.customtables", "Read") &&
                !CMSContext.CurrentUser.IsAuthorizedPerClassName(dci.ClassName, "Read"))
            {
                RedirectToAccessDenied("cms.customtables", "Read");
            }

            CustomTableItemProvider ctProvider = new CustomTableItemProvider(CMSContext.CurrentUser);
            CustomTableItem         item       = ctProvider.GetItem(itemId, dci.ClassName);
            customTableViewItem.CustomTableItem = item;
        }
    }
        public void DeleteBrand(int brandID)
        {
            CustomTableItem brand = CustomTableItemProvider.GetItem(brandID, CustomTableName);

            if (brand != null)
            {
                brand.Delete();
            }
        }
    protected void gridData_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLowerCSafe())
        {
        // Delete item action
        case "delete":
            if (CheckPermissions(PermissionsEnum.Delete))
            {
                if (CustomTableClassInfo != null)
                {
                    CustomTableItem item = CustomTableItemProvider.GetItem(ValidationHelper.GetInteger(actionArgument, 0), CustomTableClassInfo.ClassName);
                    if (item != null)
                    {
                        item.Delete();
                    }
                }

                URLHelper.RefreshCurrentPage();
            }
            break;

        // Move item up action
        case "moveup":
            if (CheckPermissions(PermissionsEnum.Modify))
            {
                if (CustomTableClassInfo != null)
                {
                    var item = CustomTableItemProvider.GetItem(ValidationHelper.GetInteger(actionArgument, 0), CustomTableClassInfo.ClassName);
                    item.Generalized.MoveObjectUp();
                }

                URLHelper.RefreshCurrentPage();
            }
            break;

        // Move item down action
        case "movedown":
            if (CheckPermissions(PermissionsEnum.Modify))
            {
                if (CustomTableClassInfo != null)
                {
                    var item = CustomTableItemProvider.GetItem(ValidationHelper.GetInteger(actionArgument, 0), CustomTableClassInfo.ClassName);
                    item.Generalized.MoveObjectDown();
                }

                URLHelper.RefreshCurrentPage();
            }
            break;
        }
    }
Exemplo n.º 10
0
 public static object GetDivisionName(EvaluationContext context, params object[] parameters)
 {
     try
     {
         int          divisionID   = ValidationHelper.GetInteger(parameters[0], 0);
         DivisionItem division     = CustomTableItemProvider.GetItem <DivisionItem>(divisionID);
         string       divisionName = division?.DivisionName ?? string.Empty;
         return(divisionName);
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("Kadena Macro methods", "GetDivisionName", ex.Message);
         return(string.Empty);
     }
 }
Exemplo n.º 11
0
    protected void gridData_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLowerCSafe())
        {
        // Delete item action
        case "delete":
            if (CheckPermissions("Delete"))
            {
                if (CustomTableClassInfo != null)
                {
                    CustomTableItem item = ctProvider.GetItem(ValidationHelper.GetInteger(actionArgument, 0), CustomTableClassInfo.ClassName);
                    if (item != null)
                    {
                        item.Delete();
                    }
                }

                URLHelper.Redirect(URLHelper.Url.ToString());
            }
            break;

        // Move item up action
        case "moveup":
            if (CheckPermissions("Modify"))
            {
                if (CustomTableClassInfo != null)
                {
                    ctProvider.MoveItemUp(ValidationHelper.GetInteger(actionArgument, 0), CustomTableClassInfo.ClassName);
                }

                URLHelper.Redirect(URLHelper.Url.ToString());
            }
            break;

        // Move item down action
        case "movedown":
            if (CheckPermissions("Modify"))
            {
                if (CustomTableClassInfo != null)
                {
                    ctProvider.MoveItemDown(ValidationHelper.GetInteger(actionArgument, 0), CustomTableClassInfo.ClassName);
                }

                URLHelper.Redirect(URLHelper.Url.ToString());
            }
            break;
        }
    }
Exemplo n.º 12
0
        public bool DeletePOS(int posID)
        {
            bool            isDeleted = false;
            CustomTableItem posItem   = CustomTableItemProvider.GetItem(posID, CustomTableName);

            if (posItem != null)
            {
                var isProductsExist = SKUInfoProvider.GetSKUs().WhereEquals("SKUProductCustomerReferenceNumber", posItem.GetStringValue("POSNumber", string.Empty)).Any();
                if (!isProductsExist)
                {
                    posItem.Delete();
                    isDeleted = true;
                }
            }
            return(isDeleted);
        }
Exemplo n.º 13
0
    /// <summary>
    /// Gets and updates custom table item. Called when the "Get and update item" button is pressed.
    /// Expects the CreateCustomTableItem method to be run first.
    /// </summary>
    private bool GetAndUpdateCustomTableItem()
    {
        // Create new Custom table item provider
        CustomTableItemProvider customTableProvider = new CustomTableItemProvider(CMSContext.CurrentUser);

        string customTableClassName = "customtable.sampletable";

        // Check if Custom table 'Sample table' exists
        DataClassInfo customTable = DataClassInfoProvider.GetDataClass(customTableClassName);

        if (customTable != null)
        {
            // Prepare the parameters
            string where = "ItemText LIKE N'New text'";
            int    topN    = 1;
            string columns = "ItemID";

            // Get the data set according to the parameters
            DataSet dataSet = customTableProvider.GetItems(customTableClassName, where, null, topN, columns);

            if (!DataHelper.DataSourceIsEmpty(dataSet))
            {
                // Get the custom table item ID
                int itemID = ValidationHelper.GetInteger(dataSet.Tables[0].Rows[0][0], 0);

                // Get the custom table item
                CustomTableItem updateCustomTableItem = customTableProvider.GetItem(itemID, customTableClassName);

                if (updateCustomTableItem != null)
                {
                    string itemText = ValidationHelper.GetString(updateCustomTableItem.GetValue("ItemText"), "");

                    // Set new values
                    updateCustomTableItem.SetValue("ItemText", itemText.ToLowerCSafe());

                    // Save the changes
                    updateCustomTableItem.Update();

                    return(true);
                }
            }
        }

        return(false);
    }
        public List <Brand> GetAddressBrands(int addressID)
        {
            List <CustomTableItem> addressBrandsList = CustomTableItemProvider.GetItems(AddressBrandTable)
                                                       .WhereEquals("AddressID", addressID)
                                                       .Columns("BrandID")
                                                       .ToList();
            List <CustomTableItem> brandList = new List <CustomTableItem>();

            if (addressBrandsList != null)
            {
                addressBrandsList.ForEach(b =>
                {
                    var brandData = CustomTableItemProvider.GetItem(b.GetIntegerValue("BrandID", default(int)), CustomTableName);
                    brandList.Add(brandData);
                });
                return(brandList.Select(x => CreateBrand(x)).Where(x => x != null).ToList());
            }
            return(null);
        }
Exemplo n.º 15
0
 /// <summary>
 /// updates the business unit data
 /// </summary>
 /// <param name="itemID"></param>
 private void UpdateBusinessUnit(int itemID)
 {
     try
     {
         var buData = CustomTableItemProvider.GetItem <BusinessUnitItem>(itemID);
         if (!DataHelper.DataSourceIsEmpty(buData))
         {
             buData.BusinessUnitNumber = ValidationHelper.GetLong(txtBUNumber.Text, default(int));
             buData.BusinessUnitName   = ValidationHelper.GetString(txtBUName.Text, string.Empty);
             buData.Status             = ValidationHelper.GetBoolean(ddlStatus.SelectedValue, true);
             buData.SiteID             = CurrentSite.SiteID;
             buData.Update();
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("BusinessUnit.ascx.cs", "UpdateBusinessUnit()", ex);
     }
 }
Exemplo n.º 16
0
    private string GetRegion(string City)
    {
        City = City.Trim();
        string result = string.Empty;

        if (string.IsNullOrEmpty(City))
        {
            return(string.Empty);
        }
        // Creates a new Custom table item provider
        CustomTableItemProvider customTableProvider = new CustomTableItemProvider(MembershipContext.AuthenticatedUser);

        string customTableClassName = "customtable.GeoLoc";

        // Checks if Custom table 'Sample table' exists
        DataClassInfo customTable = DataClassInfoProvider.GetDataClass(customTableClassName);

        if (customTable != null)
        {
            // Prepares the parameters
            string where = string.Format("entId in (select entEntId from customtable_geoloc where entID in (select entEntId from customtable_geoloc where (entGeoLocName='{0}' OR entGeoLocName LIKE '{0} |%'  OR entGeoLocName LIKE '%| {0} |%'  OR entGeoLocName LIKE '%| {0}') AND cast(entId as int)>=1000))", City);
            te.Text      = where;
            DataSet DataSet = customTableProvider.GetItems(customTableClassName, where, null);

            if (!DataHelper.DataSourceIsEmpty(DataSet))
            {
                // Gets the custom table item ID
                int entID = ValidationHelper.GetInteger(DataSet.Tables[0].Rows[0][0], 0);

                // Gets the custom table item
                CustomTableItem CustomTableItem = customTableProvider.GetItem(entID, customTableClassName);

                if (CustomTableItem != null)
                {
                    result = ValidationHelper.GetString(CustomTableItem.GetValue("entDDLValue"), "");
                }
            }
        }
        return(result);
    }
Exemplo n.º 17
0
 public static object GetCustomTableValue(EvaluationContext context, params object[] parameters)
 {
     if (parameters.Length == 3)
     {
         string          customTableCodeName        = ValidationHelper.GetString(parameters[0], "");
         int             customTableID              = ValidationHelper.GetInteger(parameters[1], -1);
         string          customTableReturnFieldName = ValidationHelper.GetString(parameters[2], "");
         CustomTableItem cti = CustomTableItemProvider.GetItem(customTableID, customTableCodeName);
         if (cti != null)
         {
             return(cti.GetValue(customTableReturnFieldName));
         }
         else
         {
             return(null);
         }
     }
     else
     {
         throw new NotSupportedException("Custom macro GetCustomTableValue() requires three parameters");
     }
 }
Exemplo n.º 18
0
        protected override void OnInit()
        {
            base.OnInit();

            var s3BucketName = SettingsKeyInfoProvider.GetValue(SettingsKeyNames.AmazonS3BucketName);

            if (!string.IsNullOrWhiteSpace(s3BucketName))
            {
                var environmentId = SettingsKeyInfoProvider.GetIntValue(SelectedEnvironment);
                try
                {
                    var environment = CustomTableItemProvider.GetItem <EnvironmentItem>(environmentId);
                    if (environment != null)
                    {
                        if (!string.IsNullOrWhiteSpace(environment.AmazonS3ExcludedPaths))
                        {
                            var excludedPaths = environment.AmazonS3ExcludedPaths.Split(';');
                            foreach (var path in excludedPaths)
                            {
                                StorageHelper.UseLocalFileSystemForPath(path);
                            }
                        }
                        var customAmazonProvider = new StorageProvider("CustomAmazon", "Kadena.AmazonFileSystemProvider", true)
                        {
                            CustomRootPath = s3BucketName,
                            CustomRootUrl  = Path.EnsureSlashes(Path.Combine(environment.AmazonS3Folder ?? string.Empty, "media"))
                        };
                        StorageHelper.MapStoragePath("~/", customAmazonProvider);
                    }
                }
                catch (Exception exc)
                {
                    EventLogProvider.LogException(GetType().Name, "EXCEPTION", exc);
                }
            }
            MacroContext.GlobalResolver.SetNamedSourceData("KadenaNamespace", KadenaMacroNamespace.Instance);
        }
        public void EditPOSNumber(int posId, bool status)
        {
            string customTableClassName = "KDA.POSNumber";

            try
            {
                // Gets the custom table
                DataClassInfo brandTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);
                if (brandTable != null)
                {
                    // Gets all data records from the POS table whose 'ItemId' field value equal to PosId
                    CustomTableItem customTableData = CustomTableItemProvider.GetItem(posId, customTableClassName);
                    if (customTableData != null)
                    {
                        customTableData.SetValue("Enable", ValidationHelper.GetBoolean(status, false));
                        customTableData.Update();
                    }
                }
            }
            catch (Exception ex)
            {
                EventLogProvider.LogInformation("CMSWebParts_Kadena_POS_POSForm", "GetBrands", ex.Message);
            }
        }
Exemplo n.º 20
0
    /// <summary>
    /// Lấy mã định danh mới
    /// </summary>
    /// <param name="dataYear">Mã theo năm</param>
    /// <param name="dataTable">Tiếp đầu ngữ của bảng</param>
    /// <param name="dataLen">Chiều dài số tự tăng</param>
    /// <param name="dataTXT">Mô tả về mã định danh</param>
    /// <returns>Mã định danh</returns>
    public static string Fn_Get_MaDinhDanh(string dataYear, string dataTable, int dataLen, string dataTXT)
    {
        string maDinhDanh;
        string dataYY = string.IsNullOrEmpty(dataYear) ? DateTime.Now.Year.ToString().Substring(2, 2) : dataYear.Substring(2, 2);
        // Create new Custom table item provider
        CustomTableItemProvider customTableProvider = new CustomTableItemProvider(CMSContext.CurrentUser);
        // Prepares the code name of the custom table
        string Code_MaLuuTru = "DX.MaLuuTru";
        // Check if Custom table exists
        DataClassInfo DX_MaLuuTru = DataClassInfoProvider.GetDataClass(Code_MaLuuTru);

        maDinhDanh = "19000001";
        if (DX_MaLuuTru != null)
        {
            // Prepare the parameters
            string where = string.Format("MaTXT = '{0}{1}'", dataTable, dataYY);
            // Get the data set according to the parameters
            DataSet dataSet = customTableProvider.GetItems(Code_MaLuuTru, where, null, 1, "ItemID");
            if (!DataHelper.DataSourceIsEmpty(dataSet))
            {
                // Get the custom table item ID
                int itemID = ValidationHelper.GetInteger(dataSet.Tables[0].Rows[0][0], 0);
                // Get the custom table item
                CustomTableItem DX_MaLuuTru_Item = customTableProvider.GetItem(itemID, Code_MaLuuTru);
                if (DX_MaLuuTru_Item != null)
                {
                    string maTXT = ValidationHelper.GetString(DX_MaLuuTru_Item.GetValue("MaTXT"), "");
                    int    maNUM = ValidationHelper.GetInteger(DX_MaLuuTru_Item.GetValue("MaNUM"), 0);
                    int    maLEN = ValidationHelper.GetInteger(DX_MaLuuTru_Item.GetValue("MaLEN"), 0);

                    // Set new values
                    DX_MaLuuTru_Item.SetValue("MaNUM", maNUM + 1);
                    // Save the changes
                    DX_MaLuuTru_Item.Update();

                    StringBuilder sb      = new StringBuilder();
                    string        newText = sb.Append('0', maLEN - maNUM.ToString().Length).ToString() + maNUM + 1;
                    maDinhDanh = maTXT + newText;
                }
            }
            else
            {
                // Create new custom table item
                CustomTableItem newItem = new CustomTableItem(Code_MaLuuTru, customTableProvider);

                // Set the ItemText field value
                newItem.SetValue("MaTXT", dataTable + dataYY);
                newItem.SetValue("maNUM", 1);
                newItem.SetValue("maLEN", dataLen);
                newItem.SetValue("ActiveNUM", true);
                newItem.SetValue("MoTaTXT", dataTXT);
                // Insert the custom table item into database
                newItem.Insert();

                StringBuilder sb      = new StringBuilder();
                string        newText = dataTable + dataYY + sb.Append('0', dataLen - 0.ToString().Length).ToString() + 1;
                maDinhDanh = newText;
            }
        }
        // Return
        return(maDinhDanh);
    }
Exemplo n.º 21
0
    public void LoadIndividualData(int pageFrom, int pageTo)
    {
        StringBuilder documentsAddedStatus = new StringBuilder();

        string Query = "select * from (select distinct MasterCustomerId,LabelName,ROW_NUMBER() over (ORDER BY MasterCustomerId) AS Number from dbo.Sme_CommiteesMaster) as com where Number>=" + pageFrom + "AND Number<=" + pageTo;

        var      queryToGetCommittees = new QueryParameters(Query, null, CMS.DataEngine.QueryTypeEnum.SQLQuery, false);
        DataSet  ds = ConnectionHelper.ExecuteQuery(queryToGetCommittees);  //ExecQuery(Query); //("pb.account_types.select_accounts", null, where, null);
        string   CommitteeMemberId            = string.Empty;
        DateTime BeginDate                    = new DateTime();
        string   CommitteeMasterCustomer      = string.Empty;
        string   CommitteeMemberLastFirstName = string.Empty;
        string   CommitteeSubCustomer         = string.Empty;
        DateTime EndDate                        = new DateTime();
        string   MemberAddressId                = string.Empty;
        string   MemberAddressTypeCodeString    = string.Empty;
        string   MemberMasterCustomer           = string.Empty;
        string   ParticipationStatusCodeString  = string.Empty;
        string   PositionCodeDescriptionDisplay = string.Empty;
        string   PositionCodeString             = string.Empty;
        string   VotingStatusCodeString         = string.Empty;
        string   CommitteeLabelName             = string.Empty;

        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                Uri ServiceUri =
                    new Uri("http://smemitst.personifycloud.com/PersonifyDataServices/PersonifyDatasme.svc");
                PersonifyEntitiesBase DataAccessLayer = new PersonifyEntitiesBase(ServiceUri);
                DataAccessLayer.Credentials = new NetworkCredential("admin", "admin");
                var CommiteeMembers =
                    DataAccessLayer.CommitteeMembers.Where(p => p.CommitteeMasterCustomer == dr["MasterCustomerId"])
                    .Select(o => o)
                    .ToList();
                if (CommiteeMembers != null)
                {
                    foreach (var member in CommiteeMembers)
                    {
                        CommitteeMemberId            = member.CommitteeMemberId.ToString();
                        BeginDate                    = Convert.ToDateTime(member.BeginDate);
                        CommitteeMasterCustomer      = member.CommitteeMasterCustomer;
                        CommitteeMemberLastFirstName = member.CommitteeMemberLastFirstName;
                        CommitteeSubCustomer         = member.CommitteeSubCustomer.ToString();
                        MemberAddressId              = member.MemberAddressId.ToString();

                        MemberAddressTypeCodeString    = member.MemberAddressTypeCodeString;
                        MemberMasterCustomer           = member.MemberMasterCustomer;
                        ParticipationStatusCodeString  = member.ParticipationStatusCodeString;
                        PositionCodeDescriptionDisplay = member.PositionCodeDescriptionDisplay.ToString();


                        PositionCodeString     = member.PositionCodeString;
                        VotingStatusCodeString = member.VotingStatusCodeString.ToString();
                        CommitteeLabelName     = member.CommitteeLabelName;
                        EndDate = Convert.ToDateTime(member.EndDate);

                        string customTableClassName = "Sme.CommiteesMembers";
                        string where = "CommitteeMemberId='" + CommitteeMemberId + "' AND CommitteeMemberLastFirstName='" + CommitteeMemberLastFirstName.Replace("'", "''") + "'";

                        // Check if Custom table 'Sme.CommiteesMembers' exists
                        DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);

                        DataSet customTableRecord = CustomTableItemProvider.GetItems(customTableClassName, where);

                        int memberID = 0;

                        if (!DataHelper.DataSourceIsEmpty(customTableRecord))
                        {
                            // Get the custom table item ID
                            memberID = ValidationHelper.GetInteger(customTableRecord.Tables[0].Rows[0][0], 0);
                        }


                        if (customTable != null)
                        {
                            if (memberID == 0)
                            {
                                if (EndDate >= DateTime.Now ||
                                    PositionCodeDescriptionDisplay.ToLower().Contains("president"))
                                {
                                    // Create new item for custom table with "Sme.CommiteesMembers" code name
                                    CustomTableItem item = CustomTableItem.New("Sme.CommiteesMembers");
                                    item.SetValue("CommitteeMemberId", CommitteeMemberId);
                                    item.SetValue("BeginDate", BeginDate);
                                    item.SetValue("CommitteeMasterCustomer", CommitteeMasterCustomer);
                                    item.SetValue("CommitteeMemberLastFirstName", CommitteeMemberLastFirstName.Replace("'", "''"));
                                    item.SetValue("CommitteeSubCustomer", CommitteeSubCustomer);

                                    item.SetValue("MemberAddressId", MemberAddressId);
                                    item.SetValue("MemberAddressTypeCodeString", MemberAddressTypeCodeString);
                                    item.SetValue("MemberMasterCustomer", MemberMasterCustomer);
                                    item.SetValue("ParticipationStatusCodeString", ParticipationStatusCodeString);
                                    item.SetValue("PositionCodeDescriptionDisplay", PositionCodeDescriptionDisplay);
                                    item.SetValue("PositionCodeString", PositionCodeString);

                                    item.SetValue("VotingStatusCodeString", VotingStatusCodeString);
                                    item.SetValue("CommitteeLabelName", CommitteeLabelName);
                                    item.SetValue("EndDate", EndDate);
                                    item.Insert();
                                }

                                /*documentsAddedStatus.Append(
                                 *  "Added CommitteeLabelName : " + CommitteeLabelName + " in the CommitteeMemberId: "
                                 + CommitteeMemberId + "at" + DateTime.Now + Environment.NewLine);*/
                            }
                            else
                            {
                                if (!DataHelper.DataSourceIsEmpty(customTableRecord))
                                {
                                    // Get the custom table item
                                    CustomTableItem updateItem = CustomTableItemProvider.GetItem(memberID, customTableClassName);

                                    if (updateItem != null)
                                    {
                                        if (EndDate >= DateTime.Now ||
                                            PositionCodeDescriptionDisplay.ToLower().Contains("president"))
                                        {
                                            //updateItem.SetValue("CommitteeMemberId", CommitteeMemberId);
                                            updateItem.SetValue("BeginDate", BeginDate);
                                            updateItem.SetValue("CommitteeMasterCustomer", CommitteeMasterCustomer);
                                            updateItem.SetValue("CommitteeMemberLastFirstName", CommitteeMemberLastFirstName.Replace("'", "''"));
                                            updateItem.SetValue("CommitteeSubCustomer", CommitteeSubCustomer);

                                            updateItem.SetValue("MemberAddressId", MemberAddressId);
                                            updateItem.SetValue(
                                                "MemberAddressTypeCodeString",
                                                MemberAddressTypeCodeString);
                                            updateItem.SetValue("MemberMasterCustomer", MemberMasterCustomer);
                                            updateItem.SetValue(
                                                "ParticipationStatusCodeString",
                                                ParticipationStatusCodeString);
                                            updateItem.SetValue(
                                                "PositionCodeDescriptionDisplay",
                                                PositionCodeDescriptionDisplay);
                                            updateItem.SetValue("PositionCodeString", PositionCodeString);

                                            updateItem.SetValue("VotingStatusCodeString", VotingStatusCodeString);
                                            updateItem.SetValue("CommitteeLabelName", CommitteeLabelName);
                                            updateItem.SetValue("EndDate", EndDate);
                                            updateItem.Update();

                                            /*documentsAddedStatus.Append(
                                             * "Updated CommitteeLabelName : " + CommitteeLabelName + " in the CommitteeMemberId: "
                                             + CommitteeMemberId + "at" + DateTime.Now + Environment.NewLine);*/
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                /*string rootFolder = "CMSWebParts";
                 * string folderName = "SME";
                 * string fileName = "CommitteeMembersStatusLogged.txt";
                 * string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, rootFolder, folderName, fileName);
                 *
                 * using (StreamWriter writer = new StreamWriter(filePath, true))
                 * {
                 *  writer.WriteLine(documentsAddedStatus);
                 *  writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                 *  writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                 * }*/
            }
        }
    }
Exemplo n.º 22
0
    /// <summary>
    /// Gets and updates custom table item. Called when the "Get and update item" button is pressed.
    /// Expects the CreateCustomTableItem method to be run first.
    /// </summary>
    private bool GetAndUpdateCustomTableItem()
    {
        // Create new Custom table item provider
        CustomTableItemProvider customTableProvider = new CustomTableItemProvider(CMSContext.CurrentUser);

        string customTableClassName = "customtable.sampletable";

        // Check if Custom table 'Sample table' exists
        DataClassInfo customTable = DataClassInfoProvider.GetDataClass(customTableClassName);
        if (customTable != null)
        {
            // Prepare the parameters
            string where = "ItemText LIKE N'New text'";
            int topN = 1;
            string columns = "ItemID";

            // Get the data set according to the parameters
            DataSet dataSet = customTableProvider.GetItems(customTableClassName, where, null, topN, columns);

            if (!DataHelper.DataSourceIsEmpty(dataSet))
            {
                // Get the custom table item ID
                int itemID = ValidationHelper.GetInteger(dataSet.Tables[0].Rows[0][0], 0);

                // Get the custom table item
                CustomTableItem updateCustomTableItem = customTableProvider.GetItem(itemID, customTableClassName);

                if (updateCustomTableItem != null)
                {
                    string itemText = ValidationHelper.GetString(updateCustomTableItem.GetValue("ItemText"), "");

                    // Set new values
                    updateCustomTableItem.SetValue("ItemText", itemText.ToLowerCSafe());

                    // Save the changes
                    updateCustomTableItem.Update();

                    return true;
                }
            }
        }

        return false;
    }
        private CustomTableItem GetBusinessUnitItem(CustomTableItem businessUnitItemID)
        {
            int itemID = businessUnitItemID.GetIntegerValue("BusinessUnitID", 0);

            return(CustomTableItemProvider.GetItem(itemID, BusinessUnitsCustomTableName));
        }