コード例 #1
0
    /// <summary>
    /// Creates custom table item. Called when the "Create item" button is pressed.
    /// </summary>
    private bool CreateCustomTableItem()
    {
        // Create new Custom table item provider
        CustomTableItemProvider customTableProvider = new CustomTableItemProvider(CMSContext.CurrentUser);

        // Prepare the parameters
        string customTableClassName = "customtable.sampletable";

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

        if (customTable != null)
        {
            // Create new custom table item
            CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName, customTableProvider);

            // Set the ItemText field value
            newCustomTableItem.SetValue("ItemText", "New text");

            // Insert the custom table item into database
            newCustomTableItem.Insert();

            return(true);
        }

        return(false);
    }
コード例 #2
0
ファイル: Default.aspx.cs プロジェクト: KuduApps/Kentico
    /// <summary>
    /// Creates custom table item. Called when the "Create item" button is pressed.
    /// </summary>
    private bool CreateCustomTableItem()
    {
        // Create new Custom table item provider
        CustomTableItemProvider customTableProvider = new CustomTableItemProvider(CMSContext.CurrentUser);

        // Prepare the parameters
        string customTableClassName = "customtable.sampletable";

        // Check if Custom table 'Sample table' exists
        DataClassInfo customTable = DataClassInfoProvider.GetDataClass(customTableClassName);
        if (customTable != null)
        {
            // Create new custom table item
            CustomTableItem newCustomTableItem = new CustomTableItem(customTableClassName, customTableProvider);

            // Set the ItemText field value
            newCustomTableItem.SetValue("ItemText", "New text");

            // Insert the custom table item into database
            newCustomTableItem.Insert();

            return true;
        }

        return false;
    }
コード例 #3
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "add")
        {
            // Add itemId in customtable_shippingextension.shippingoptionid

            // Creates new Custom table item provider
            CustomTableItemProvider customTableProvider = new CustomTableItemProvider(MembershipContext.AuthenticatedUser);

            // Prepares the parameters
            string customTableClassName = "customtable.shippingextension";

            // Checks if Custom table exists
            DataClassInfo customTable = DataClassInfoProvider.GetDataClass(customTableClassName);
            if (customTable != null)
            {
                // Creates new custom table item
                CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName, customTableProvider);

                // Sets the ItemText field value
                newCustomTableItem.SetValue("ShippingOptionId", actionArgument.ToString());
                newCustomTableItem.SetValue("LocalContact", string.Empty);
                newCustomTableItem.SetValue("Enabled", true);
                newCustomTableItem.SetValue("ProcessingMode", 0);

                // Inserts the custom table item into database
                newCustomTableItem.Insert();
            }
            //Response.Redirect("ShippingExtension_List.aspx");
            Response.Redirect(Request.Url.ToString());
        }
    }
コード例 #4
0
    private bool CreateCustomTableItem(string Desc, int Qty)
    {
        // Creates new Custom table item provider
        CustomTableItemProvider customTableProvider = new CustomTableItemProvider(MembershipContext.AuthenticatedUser);

        // Prepares the parameters
        string customTableClassName = "customtable.customBundle";

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

        if (customTable != null)
        {
            // Creates new custom table item
            CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName, customTableProvider);

            // Sets the ItemText field value
            newCustomTableItem.SetValue("Quantity", Qty);
            newCustomTableItem.SetValue("Description", Desc);
            newCustomTableItem.SetValue("Enabled", true);
            // Inserts the custom table item into database
            newCustomTableItem.Insert();

            return(true);
        }

        return(false);
    }
コード例 #5
0
        public void InsertCampaignOrdersInProgress(int campaignID)
        {
            DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);

            if (customTable != null)
            {
                CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName);
                newCustomTableItem.SetValue("CampaignID", campaignID);
                newCustomTableItem.SetValue("IsCampaignOrdersInProgress", true);
                newCustomTableItem.SetValue("IsCampaignOrdersFailed", false);
                newCustomTableItem.Insert();
            }
        }
コード例 #6
0
        public void InsertIBTFAdjustmentRecord(IBTFAdjustment inboundAdjustment)
        {
            DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(IBTFAdjustmentCustomTableName);

            if (customTable != null)
            {
                CustomTableItem newCustomTableItem = CustomTableItem.New(IBTFAdjustmentCustomTableName);
                newCustomTableItem.SetValue("SKUID", inboundAdjustment.SKUID);
                newCustomTableItem.SetValue("UserID", inboundAdjustment.UserID);
                newCustomTableItem.SetValue("CampaignID", inboundAdjustment.CampaignID);
                newCustomTableItem.SetValue("OrderedQuantity", inboundAdjustment.OrderedQuantity);
                newCustomTableItem.SetValue("OrderedProductPrice", inboundAdjustment.OrderedProductPrice);
                newCustomTableItem.SetValue("SiteName", SiteContext.CurrentSiteName);
                newCustomTableItem.Insert();
            }
        }
コード例 #7
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();
                    }
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// This method will save the allocated product w.r.t to User in custome tabel
        /// </summary>
        /// <param name="productID">The id of the product which user wants to Allocate</param>
        private void AllocateProductToUsers(int productID)
        {
            string        customTableClassName = "KDA.UserAllocatedProducts";
            DataClassInfo customTable          = DataClassInfoProvider.GetDataClassInfo(customTableClassName);

            if (customTable != null)
            {
                CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName);
                foreach (AllocateProduct User in lstUsers)
                {
                    newCustomTableItem.SetValue("UserID", User.UserID);
                    newCustomTableItem.SetValue("ProductID", productID);
                    newCustomTableItem.SetValue("Quantity", User.Quantity);
                    newCustomTableItem.SetValue("EmailID", User.EmailID);
                    newCustomTableItem.Insert();
                }
            }
        }
コード例 #9
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "add")
        {
            CountryInfo country = CountryInfoProvider.GetCountryInfo(Convert.ToInt32(actionArgument));
            // Check if country can be added in the ShippingExtension
            if (CheckCountry(Convert.ToInt32(actionArgument)))
            {
                // Add itemId in customtable_shippingextension.shippingoptionid
                // Creates new Custom table item provider
                CustomTableItemProvider customTableProvider = new CustomTableItemProvider(MembershipContext.AuthenticatedUser);

                // Prepares the parameters
                string customTableClassName = "customtable.shippingextensioncountry";

                // Checks if Custom table exists
                DataClassInfo customTable = DataClassInfoProvider.GetDataClass(customTableClassName);
                if (customTable != null)
                {
                    // Creates new custom table item
                    CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName, customTableProvider);

                    // Sets the ItemText field value
                    newCustomTableItem.SetValue("ShippingOptionId", shippingExtensionID.ToString());
                    newCustomTableItem.SetValue("ShippingCountryId", actionArgument.ToString());
                    newCustomTableItem.SetValue("ShippingBase", 0);
                    newCustomTableItem.SetValue("LocalContact", string.Empty);
                    newCustomTableItem.SetValue("Enabled", true);
                    newCustomTableItem.SetValue("ProcessingMode", 1);
                    newCustomTableItem.SetValue("UnitPrice", 0);
                    // Inserts the custom table item into database
                    newCustomTableItem.Insert();
                }
                //Response.Redirect(Request.Url.ToString());
                ShowInformation(string.Format("<b>{0}</b> added for <b>{1}</b>", country.CountryName, GetShippingOptionName(shippingExtensionID.ToString())));
            }
            else
            {
                ShowError(string.Format("<b>{0}</b> is already defined for <b>{1}</b>", country.CountryName, GetShippingOptionName(shippingExtensionID.ToString())));
            }
        }
    }
コード例 #10
0
 /// <summary>
 /// Update the Product allocation
 /// </summary>
 /// <param name="productID">The id of the product which user wants to Update</param>
 private void UpdateAllocateProduct(int productID)
 {
     try
     {
         string        customTableClassName = "KDA.UserAllocatedProducts";
         DataClassInfo customTable          = DataClassInfoProvider.GetDataClassInfo(customTableClassName);
         if (customTable != null)
         {
             var customTableData = CustomTableItemProvider.GetItems(customTableClassName)
                                   .WhereStartsWith("ProductID", productID.ToString());
             foreach (CustomTableItem customitem in customTableData)
             {
                 int index = lstUsers.FindIndex(item => item.UserID == ValidationHelper.GetInteger(customitem.GetValue("UserID"), 0));
                 if (index > -1)
                 {
                     customitem.SetValue("Quantity", lstUsers[index].Quantity);
                     customitem.Update();
                     lstUsers.RemoveAt(index);
                 }
                 else
                 {
                     customitem.Delete();
                     lstUsers.RemoveAt(index);
                 }
             }
         }
         CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName);
         foreach (AllocateProduct User in lstUsers)
         {
             newCustomTableItem.SetValue("UserID", User.UserID);
             newCustomTableItem.SetValue("ProductID", productID);
             newCustomTableItem.SetValue("Quantity", User.Quantity);
             newCustomTableItem.SetValue("EmailID", User.EmailID);
             newCustomTableItem.Insert();
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("Product allocation update", "EXCEPTION", ex);
     }
 }
コード例 #11
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);
        }
コード例 #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Uri ServiceUri = new Uri(SUri);
        PersonifyEntitiesBase DataAccessLayer = new PersonifyEntitiesBase(ServiceUri);

        DataAccessLayer.Credentials = new NetworkCredential(UserName, Password);
        _webControlParameters       = DataAccessLayer.WebControlParameters.ToList();


        if (_webControlParameters.Count > 0)
        {
            foreach (var x  in _webControlParameters)
            {
                //

                string customTableClassName = "Sme.personifyPages";
                string where = "ParameterName='" + x.ParameterName + "'";

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


                CustomTableItem item = CustomTableItem.New("Sme.personifyPages");
                item.SetValue("ParameterValue", x.ParameterValue);
                item.SetValue("ParameterName", x.ParameterName);
                item.Insert();
                //DataSet customTableRecord = CustomTableItemProvider.GetItems(customTableClassName, where);

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

                //if (customTable != null)
                //{
                //    if (ItemID == 0)
                //    {
                //        CustomTableItem item = CustomTableItem.New("Sme.CommiteesMembers");
                //        item.SetValue("ParameterValue", x.ParameterValue);
                //        item.SetValue(" ParameterName", x.ParameterName);
                //        item.Insert();
                //    }

                //    else
                //    {

                //        if (!DataHelper.DataSourceIsEmpty(customTableRecord))
                //        {
                //            CustomTableItem updateItem = CustomTableItemProvider.GetItem(ItemID, customTableClassName);
                //            if (updateItem != null)
                //            {
                //                updateItem.SetValue("ParameterValue", x.ParameterValue);
                //                updateItem.SetValue(" ParameterName", x.ParameterName);

                //                updateItem.Update();
                //            }
                //        }
                //    }
                //}

                ///
                Response.Write(x.ParameterValue + "---" + x.ParameterName + "<br/>");
            }
        }
    }
コード例 #13
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);
    }
コード例 #14
0
    private Boolean CreateCustomTableItem(DataClassInfo customTable, DataRow dr)
    {
        if (customTable != null)
        {
            // Creates new custom table item

            CustomTableItem newCustomTableItem = CustomTableItem.New(customTable.ClassName, _customTableProvider);



            // Sets the ItemText field value
            try
            {
                if (_customTable == null)
                {
                    _customTable = (Session["_customTable"] != null ? (DataSet)Session["_customTable"] : null);
                }
                int i = 0;
                if (_customTable != null)
                {
                    foreach (DataColumn column in _customTable.Tables[0].Columns)
                    {
                        if (column.ColumnName.LastIndexOf("Item") == -1)
                        {
                            string temp = "";
                            object aaa  = default_value(column.ColumnName, out temp);
                            aaa = (aaa != null ? aaa : null);
                            if (aaa != null)
                            {
                                object vl = null;

                                /*
                                 * if (default_value_int(column.ColumnName))
                                 * {
                                 *
                                 *   vl = double_parse(dr[aaa.ToString()].ToString().Trim().Replace("$", "").Replace(",", ""));
                                 * }
                                 * else
                                 * {
                                 *   if (column.ColumnName == "Views") vl = int_parse(dr[aaa.ToString()].ToString().Trim());
                                 *   else
                                 *       if (column.ColumnName == "Featured") vl = bool_parse(dr[aaa.ToString()].ToString().Trim());
                                 *   else
                                 *           if (column.ColumnName == "Model") vl = dr[aaa.ToString()].ToString().Trim().Split('"')[0];
                                 *           else
                                 *       vl = dr[aaa.ToString()].ToString().Trim();
                                 *
                                 *
                                 *
                                 * }
                                 */
                                try
                                {
                                    vl = type_field(dr[aaa.ToString()].ToString());
                                    if (vl != null)
                                    {
                                        newCustomTableItem.SetValue(column.ColumnName, vl);
                                    }
                                }
                                catch (Exception exx)
                                {
                                    Literal1.Text += "<p>- Column " + temp + " error:" + exx.Message + "</p>";
                                }
                            }
                        }
                    }

                    newCustomTableItem.Insert();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Literal1.Text += e.Message + "<br>";
                return(false);
            }
        }


        return(false);
    }
コード例 #15
0
    /// <summary>
    /// Figure out using the Join Table which categories need to be removed and which added
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Form_OnAfterSaveJoinTable(object sender, EventArgs e)
    {
        //dont save data for filter forms
        if (sender is CMS.FormEngine.Web.UI.FilterForm)
        {
            return;
        }

        // Add key so it will load the new data even though it is a 'postback' after this.
        DataClassInfo JoinTableClassInfo = DataClassInfoProvider.GetDataClassInfo(JoinTableName);

        if (JoinTableClassInfo != null)
        {
            List <string> SelectedObjectRefIDs = GetSelectedObjects();
            List <string> CurrentObjectRefIDs  = GetCurrentObjects();

            List <string> ObjectsToAdd    = SelectedObjectRefIDs.Where(x => !CurrentObjectRefIDs.Contains(x)).ToList();
            List <string> ObjectsToRemove = CurrentObjectRefIDs.Where(x => !SelectedObjectRefIDs.Contains(x)).ToList();

            if (ObjectsToAdd.Count > 0)
            {
                foreach (string ObjectToAdd in ObjectsToAdd)
                {
                    // Custom Tables
                    if (JoinTableClassInfo.ClassIsCustomTable)
                    {
                        CustomTableItem newCustomTableItem = CustomTableItem.New(JoinTableName);
                        SetBaseInfoItemValues(newCustomTableItem, GetProperObjectValue(ObjectToAdd), JoinTableClassInfo.ClassName);
                        newCustomTableItem.Insert();
                    }
                    else
                    {
                        // Create a dynamic BaseInfo object of the right type.
                        var JoinTableClassFactory = new InfoObjectFactory(JoinTableClassInfo.ClassName);
                        if (JoinTableClassFactory.Singleton == null)
                        {
                            AddError("Class does not have TypeInfo and TypeInfoProvider generated.  Must generate " + JoinTableClassInfo.ClassName + " Code before can bind.");
                            return;
                        }
                        BaseInfo newJoinObj = ((BaseInfo)JoinTableClassFactory.Singleton);
                        SetBaseInfoItemValues(newJoinObj, GetProperObjectValue(ObjectToAdd), JoinTableClassInfo.ClassName);
                        InsertObjectHandler(newJoinObj);
                    }
                }
            }
            if (ObjectsToRemove.Count > 0)
            {
                foreach (string ObjectToRemove in ObjectsToRemove)
                {
                    // Custom Table logic
                    if (JoinTableClassInfo.ClassIsCustomTable)
                    {
                        CustomTableItemProvider.GetItems(JoinTableClassInfo.ClassName).WhereEquals(JoinTableLeftFieldName, CurrentItemIdentification)
                        .WhereEquals(JoinTableRightFieldName, GetProperObjectValue(ObjectToRemove))
                        .ToList().ForEach(x => ((CustomTableItem)x).Delete());
                    }
                    else
                    {
                        new ObjectQuery(JoinTableClassInfo.ClassName)
                        .WhereEquals(JoinTableLeftFieldName, CurrentItemIdentification)
                        .WhereEquals(JoinTableRightFieldName, GetProperObjectValue(ObjectToRemove))
                        .ToList().ForEach(x => x.Delete());
                    }
                }
            }
        }
    }
コード例 #16
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);
                 * }*/
            }
        }
    }
コード例 #17
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Creates new Custom table item provider
        CustomTableItemProvider customTableProvider = new CustomTableItemProvider(MembershipContext.AuthenticatedUser);

        // Prepares the parameters
        string customTableClassName = "customtable.shippingextensionpricing";

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

        if (customTable != null)
        {
            // VALIDATION RULES
            int     shippingUnitTo = -1, shippingUnitFrom = Convert.ToInt32(txtShippingUnitFrom.Text);
            decimal price = 0;



            if (!string.IsNullOrEmpty(txtShippingUnitTo.Text))
            {
                txtShippingUnitTo.Text = txtShippingUnitTo.Text.Trim();

                // Ensures integer value entered in txtShippingUnitTo
                try
                {
                    shippingUnitTo = Convert.ToInt32(txtShippingUnitTo.Text);
                }
                catch
                {
                    ShowError(string.Format("<b>{0}</b> is not valid for <u><b>Shipping unit to</b></u>", txtShippingUnitTo.Text));
                    return;
                }

                // Ensures txtShippingUnitTo > txtShippingUnitFrom
                if (shippingUnitTo <= shippingUnitFrom && shippingUnitTo != -1)
                {
                    ShowError(string.Format("<u><b>Shipping unit to</b></u> must be greater than {0}", txtShippingUnitFrom.Text));
                    return;
                }

                // Ensures price exists
                if (string.IsNullOrEmpty(txtPrice.Text.Trim()))
                {
                    ShowError("Price must be entered");
                    return;
                }
            }

            // Ensures decimal value entered in txtPrice if txtShippingUnitTo is filled
            try
            {
                price = Convert.ToDecimal(txtPrice.Text);
            }
            catch
            {
                if (!string.IsNullOrEmpty(txtShippingUnitTo.Text.Trim()))
                {
                    ShowError(string.Format("<u><b>Price</b></u> {0} is not valid", txtPrice.Text));
                    return;
                }
            }

            // Creates new custom table item
            CustomTableItem newCustomTableItem = CustomTableItem.New(customTableClassName, customTableProvider);
            // Sets the ItemText field value
            newCustomTableItem.SetValue("ShippingExtensionCountryId", mShippingExtensionPricingID);
            newCustomTableItem.SetValue("ShippingUnitFrom", int.Parse(txtShippingUnitFrom.Text));
            newCustomTableItem.SetValue("ShippingUnitTo", shippingUnitTo);
            newCustomTableItem.SetValue("ShippingUnitPrice", price);

            // Inserts the custom table item into database
            newCustomTableItem.Insert();
        }
        Response.Redirect(string.Format("ShippingExtension_Edit_Pricing.aspx?ItemID={0}", mShippingExtensionPricingID.ToString()));
    }