예제 #1
0
        /// <summary>
        /// Adds the specified import column rule.
        /// </summary>
        /// <param name="importColumnRule">The import column rule.</param>
        /// <returns></returns>
        public tbl_ImportColumnRule Add(tbl_ImportColumnRule importColumnRule)
        {
            if (importColumnRule.ID == Guid.Empty)
            {
                importColumnRule.ID = Guid.NewGuid();
            }
            _dataContext.tbl_ImportColumnRule.AddObject(importColumnRule);
            _dataContext.SaveChanges();

            return(importColumnRule);
        }
예제 #2
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        protected void Save()
        {
            var import = DataManager.Import.SelectByID(SiteId, _importId) ?? new tbl_Import();

            // Save Import
            import.SiteID                  = SiteId;
            import.Name                    = txtName.Text;
            import.ImportTable             = byte.Parse(ddlImportTable.SelectedValue);
            import.SheetName               = ddlSheet.SelectedValue;
            import.FirstRow                = int.Parse(txtFirstRow.Text);
            import.FirstColumn             = int.Parse(txtFirstColumn.Text);
            import.IsFirstRowAsColumnNames = cbIsFirstRowAsColumnNames.Checked;
            import.Type                    = (int)ddlType.SelectedValue.ToEnum <ImportType>();
            import.CsvSeparator            = ddlType.SelectedValue.ToEnum <ImportType>() == ImportType.Csv ? CsvSeparator : null;

            if (import.ID == Guid.Empty)
            {
                import.ID = Guid.NewGuid();
                DataManager.Import.Add(import);
            }
            else
            {
                DataManager.Import.Update(import);
            }

            _importId = import.ID;

            // Save Import Columns
            DataManager.ImportColumn.DeleteByImportID(import.ID);
            byte order = 1;

            foreach (GridDataItem item in rgImportColumns.Items)
            {
                var importColumnID = Guid.Parse(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ID"].ToString());
                var importColumn   = new tbl_ImportColumn
                {
                    ID           = importColumnID,
                    ImportID     = import.ID,
                    Name         = ((RadTextBox)item.FindControl("txtName")).Text,
                    Source       = ((HtmlGenericControl)item.FindControl("spanSource")).InnerText,
                    SystemName   = string.Format("Column{0}", order + txtFirstColumn.Value - 1),
                    PrimaryKey   = ((CheckBox)item.FindControl("cbPrimaryKey")).Checked,
                    SecondaryKey = ((CheckBox)item.FindControl("cbSecondaryKey")).Checked,
                    Order        = order
                };
                DataManager.ImportColumn.Add(importColumn);
                order++;
            }

            // Save Import Column Rules
            DataManager.ImportColumnRules.DeleteByImportID(import.ID);
            foreach (GridDataItem item in rgImportColumnRules.Items)
            {
                var importFieldID = Guid.Parse(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ID"].ToString());
                if (!string.IsNullOrEmpty(((DropDownList)item.FindControl("ddlImportColumns")).SelectedValue))
                {
                    var importColumnRule = new tbl_ImportColumnRule
                    {
                        ImportID       = import.ID,
                        ImportFieldID  = importFieldID,
                        ImportColumnID = Guid.Parse(((DropDownList)item.FindControl("ddlImportColumns")).SelectedValue),
                        IsRequired     = ((CheckBox)item.FindControl("cbIsRequired")).Checked,
                        SQLCode        = ((RadTextBox)item.FindControl("txtSQLCode")).Text
                    };

                    /*if (((DropDownList)item.FindControl("ddlImportFieldDictionary")).Visible)
                     *  importColumnRule.ImportFieldDictionaryID = Guid.Parse(((DropDownList)item.FindControl("ddlImportFieldDictionary")).SelectedValue);
                     * else
                     *  importColumnRule.ImportFieldDictionaryID = null;*/

                    DataManager.ImportColumnRules.Add(importColumnRule);
                }
            }

            // Save Import Tags
            ucImportTag.ImportId = _importId;
            ucImportTag.Save();
        }