예제 #1
0
        protected void ProcessCategory(int productNodeId, string categoryPath)
        {
            if (!string.IsNullOrEmpty(categoryPath))
            {
                var categoryItem = FindProductCategory(categoryPath);
                if (categoryItem != null)
                {
                    RelationshipInfoProvider.AddRelationship(productNodeId, categoryItem.NodeID,
                                                             productCategoryProductRelationshipID);
                }
                // if product detail or product category are null log error and add to error tracker (add error tracking custom table)fields, product detail name, product category name and explanation of what's wrong
                else
                {
                    // Prepares the code name (class name) of the custom table to which the data record will be added
                    string customTableClassName = "PbcLinear.ProcessCategoryErrors";

                    // Gets the custom table
                    DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);
                    if (customTable != null)
                    {
                        // Creates a new custom table item
                        CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName);

                        // Sets the values for the fields of the custom table (ItemText in this case)
                        newCustomTableItem.SetValue("ProductNodeId", productNodeId);
                        newCustomTableItem.SetValue("CategoryPath", categoryPath);
                        newCustomTableItem.SetValue("Error", "categoryItem is null ");

                        if (productNodeId == 0)
                        {
                            var newError = newCustomTableItem.GetValue("Error") + " productNodeId is empty";
                            newCustomTableItem.SetValue("Error", newError);
                        }

                        if (!string.IsNullOrEmpty(categoryPath))
                        {
                            var newError = newCustomTableItem.GetValue("Error") + " categoryPath is empty";
                            newCustomTableItem.SetValue("Error", newError);
                        }

                        // Save the new custom table record into the database
                        newCustomTableItem.Insert();
                    }
                }
            }
        }
예제 #2
0
        public void AdjustUserRemainingBudget(string year, int userID, decimal adjustment)
        {
            CustomTableItem userBudgetDetails = CustomTableItemProvider.GetItems(CustomTableClassName).WhereEquals("UserID", userID).WhereEquals("Year", year).FirstOrDefault();

            if (userBudgetDetails != null)
            {
                userBudgetDetails.SetValue("UserRemainingBudget", userBudgetDetails.GetValue("UserRemainingBudget", default(decimal)) + (adjustment));
                userBudgetDetails.Update();
            }
        }
예제 #3
0
        public UserBudgetItem CreateUserBudgetWithYear(string year, int siteID, int userId)
        {
            DataClassInfo   customTable        = DataClassInfoProvider.GetDataClassInfo(CustomTableClassName);
            CustomTableItem newCustomTableItem = CustomTableItem.New(CustomTableClassName);

            if (customTable != null)
            {
                newCustomTableItem.SetValue("UserID", userId);
                newCustomTableItem.SetValue("Year", year);
                newCustomTableItem.SetValue("Budget", default(decimal));
                newCustomTableItem.SetValue("UserRemainingBudget", default(decimal));
                newCustomTableItem.SetValue("SiteID", siteID);
                newCustomTableItem.Insert();
                return(new UserBudgetItem()
                {
                    ItemID = newCustomTableItem.ItemID,
                    Budget = newCustomTableItem.GetValue("Budget", default(decimal)),
                    UserID = userId,
                    UserRemainingBudget = newCustomTableItem.GetValue("UserRemainingBudget", default(decimal)),
                    Year = year
                });
            }
            return(null);
        }
예제 #4
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);
    }
예제 #5
0
    /// <summary>
    /// Gets and bulk updates custom table items. Called when the "Get and bulk update items" button is pressed.
    /// Expects the CreateCustomTableItem method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateCustomTableItems()
    {
        // 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%'";

            // Get the data
            DataSet customTableItems = customTableProvider.GetItems(customTableClassName, where, null);
            if (!DataHelper.DataSourceIsEmpty(customTableItems))
            {
                // Loop through the individual items
                foreach (DataRow customTableItemDr in customTableItems.Tables[0].Rows)
                {
                    // Create object from DataRow
                    CustomTableItem modifyCustomTableItem = CustomTableItem.New(customTableItemDr, customTableClassName);

                    string itemText = ValidationHelper.GetString(modifyCustomTableItem.GetValue("ItemText"), "");

                    // Set new values
                    modifyCustomTableItem.SetValue("ItemText", itemText.ToUpper());

                    // Save the changes
                    modifyCustomTableItem.Update();
                }

                return(true);
            }
        }

        return(false);
    }
예제 #6
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);
    }
예제 #7
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");
     }
 }
예제 #8
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);
    }
예제 #9
0
    /// <summary>
    /// Gets and bulk updates custom table items. Called when the "Get and bulk update items" button is pressed.
    /// Expects the CreateCustomTableItem method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateCustomTableItems()
    {
        // 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%'";

            // Get the data
            DataSet customTableItems = customTableProvider.GetItems(customTableClassName, where, null);
            if (!DataHelper.DataSourceIsEmpty(customTableItems))
            {
                // Loop through the individual items
                foreach (DataRow customTableItemDr in customTableItems.Tables[0].Rows)
                {
                    // Create object from DataRow
                    CustomTableItem modifyCustomTableItem = new CustomTableItem(customTableItemDr, customTableClassName);

                    string itemText = ValidationHelper.GetString(modifyCustomTableItem.GetValue("ItemText"), "");

                    // Set new values
                    modifyCustomTableItem.SetValue("ItemText", itemText.ToUpper());

                    // Save the changes
                    modifyCustomTableItem.Update();
                }

                return true;
            }
        }

        return false;
    }