Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            AllowNullsCheckBox.Text =  " " + GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "AllowNulls").ToString();
            ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(btnUpdate);
            lblNotEmptyName.Style.Add("display", "none");
            if (!Page.IsPostBack)
            {
                ViewState["_keyLIP"] = Request["key"];
                if (Request["field"] != null)
                    ViewState["_field"] = Request["field"];
                else
                    ViewState["_field"] = null;

                ViewState[currentControlKey] = null;

                //lip = (ListImportParameters)CHelper.GetFromContext(ViewState["_keyLIP"].ToString());
                //if(lip == null)
                lip = (ListImportParameters)Session[ViewState["_keyLIP"].ToString()];
                if (lip != null)
                {
                    BindData();

                    if (!AutogenerateSystemNames)
                        Page.SetFocus(NameTextBox);
                    else
                        Page.SetFocus(FriendlyNameTextBox);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the ServerClick event of the SaveButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveButton_ServerClick(object sender, EventArgs e)
        {
            if (FormatList.Items.Count < 0)
                throw new Exception("Format is not specified");

            Page.Validate();
            if (!Page.IsValid)
                return;

            if (ViewState["_keyLIP"] != null)
            {
                //lip = (ListImportParameters)CHelper.GetFromContext(ViewState["_keyLIP"].ToString());
                //if (lip == null)
                lip = (ListImportParameters)Session[ViewState["_keyLIP"].ToString()];
                if (lip != null)
                {

                    Mediachase.Ibn.Data.Meta.Management.AttributeCollection attr = new Mediachase.Ibn.Data.Meta.Management.AttributeCollection();
                    string sDefaultValue = String.Empty;

                    IManageControl control = MainPlaceHolder.Controls[0] as IManageControl;

                    if (control != null)
                    {
                        sDefaultValue = control.GetDefaultValue(AllowNullsCheckBox.Checked);
                        attr = control.FieldAttributes;
                    }

                    if (!AllowNullsCheckBox.Checked && sDefaultValue == String.Empty)
                    {
                        if (attr.ContainsKey("NewEnum") || attr.ContainsKey("NewMultiEnum"))
                            sDefaultValue = "1";

                        ErrorMessage.Text = GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "ErrorMessage_AllowNulls").ToString();
                        return;
                    }

                    if (sDefaultValue == null)
                        sDefaultValue = String.Empty;

                    string sName;
                    if (!AutogenerateSystemNames)
                    {
                        sName = NameTextBox.Text.Trim();
                    }
                    else
                    {
                        // Generate the field name as the number of seconds elapsed since 2000-01-01
                        sName = String.Format(CultureInfo.InvariantCulture, "Field{0}", CHelper.GetDateDiffInSeconds(DateTime.UtcNow, new DateTime(2000, 1, 1)));
                    }

                    string sFriendlyName = FriendlyNameTextBox.Text.Trim();
                    if (String.IsNullOrEmpty(sFriendlyName))
                        sFriendlyName = sName;

                    try
                    {
                        string typeName = FormatList.SelectedValue;
                        if (attr.ContainsKey("NewEnum"))
                        {
                            string name = attr["EnumName"].ToString();
                            string friendlyname = attr["EnumFriendlyName"].ToString();
                            bool isPrivate = (bool)attr["EnumPrivate"];

                            attr.Remove("NewEnum");
                            attr.Remove("EnumName");
                            attr.Remove("EnumFriendlyName");
                            attr.Remove("EnumPrivate");

                            NewEnumInfo nei = new NewEnumInfo();
                            nei.Name = name;
                            nei.FriendlyName = friendlyname;
                            nei.MultipleValues = false;
                            nei.IsPrivate = isPrivate;
                            lip.NewEnumTypes.Add(nei);

                            typeName = name;
                        }
                        //NewMultiEnum
                        if (attr.ContainsKey("NewMultiEnum"))
                        {
                            string name = attr["EnumName"].ToString();
                            string friendlyname = attr["EnumFriendlyName"].ToString();
                            bool isPrivate = (bool)attr["EnumPrivate"];

                            attr.Remove("NewMultiEnum");
                            attr.Remove("EnumName");
                            attr.Remove("EnumFriendlyName");
                            attr.Remove("EnumPrivate");

                            NewEnumInfo nei = new NewEnumInfo();
                            nei.Name = name;
                            nei.FriendlyName = friendlyname;
                            nei.MultipleValues = true;
                            nei.IsPrivate = isPrivate;
                            lip.NewEnumTypes.Add(nei);

                            typeName = name;
                        }

                        MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[FormatList.SelectedValue];
                        if (mft != null && mft.McDataType == McDataType.Enum &&
                            attr.ContainsKey("EnumFriendlyName"))
                        {
                            mft.FriendlyName = attr["EnumFriendlyName"].ToString();
                            attr.Remove("EnumFriendlyName");
                        }

                        MappingRule mr = null;
                        if (ViewState["_field"] != null)
                        {
                            mr = lip.GetRuleByMetaField(ViewState["_field"].ToString());
                            lip.RemoveNewMetaField(ViewState["_field"].ToString());
                        }

                        lip.AddNewMetaField(sName, sFriendlyName, typeName, AllowNullsCheckBox.Checked, sDefaultValue, attr);
                        if (mr != null)
                            mr.FieldName = sName;
                        Session[ViewState["_keyLIP"].ToString()] = lip;
                        CommandParameters cp = new CommandParameters(_commandName);
                        Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());
                        //CHelper.AddToContext("NeedToChangeDataSource", true);
                    }
                    catch (MetaFieldAlreadyExistsException)
                    {
                    }

                    //NameTextBox.Text = String.Empty;
                    //FriendlyNameTextBox.Text = String.Empty;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Handles the DeleteCommand event of the DataGrid control.
 /// </summary>
 /// <param name="source">The source of the event.</param>
 /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
 void dgMapping_DeleteCommand(object source, DataGridCommandEventArgs e)
 {
     lip = (ListImportParameters)ViewState["lip"];
     string mfName = e.CommandArgument.ToString();
     lip.RemoveNewMetaField(mfName);
     lip.RemoveRuleByMetaField(mfName);
     ViewState["lip"] = lip;
     Session[_keyLIP] = lip;
     BindDG();
 }
Esempio n. 4
0
        /// <summary>
        /// Handles the ActiveStepChanged event of the ucWizard control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void ucWizard_ActiveStepChanged(object sender, EventArgs e)
        {
            //step2
            if (ucWizard.ActiveStep.ID == "step2")
            {
                #region upload file
                if (fSourceFile.PostedFile != null && fSourceFile.PostedFile.ContentLength > 0)
                {
                    txtTitle.Text = Path.GetFileNameWithoutExtension(fSourceFile.PostedFile.FileName);
                    ProcessFileCache(Server.MapPath(Mediachase.UI.Web.Util.CommonHelper.ChartPath));
                    String dir = Mediachase.UI.Web.Util.CommonHelper.ChartPath;
                    string wwwpath = dir + Guid.NewGuid().ToString("N");
                    wwwpath += Path.GetExtension(fSourceFile.PostedFile.FileName);

                    hdnFilePath.Value = wwwpath;
                    using (Stream sw = File.Create(Server.MapPath(wwwpath)))
                    {
                        fSourceFile.PostedFile.InputStream.Seek(0, SeekOrigin.Begin);
                        System.IO.BinaryReader br = new System.IO.BinaryReader(fSourceFile.PostedFile.InputStream);
                        int iBufferSize = 655360; // 640 KB
                        byte[] outbyte = br.ReadBytes(iBufferSize);

                        while (outbyte.Length > 0)
                        {
                            sw.Write(outbyte, 0, outbyte.Length);
                            outbyte = br.ReadBytes(iBufferSize);
                        }
                        br.Close();
                    }
                }
                #endregion

                BindTree();
            }

            //step3
            if (ucWizard.ActiveStep.ID == "step3")
            {
                trCSV.Visible = (rbSourceType.SelectedIndex == 2);
                trList.Visible = !trCSV.Visible;

                #region file parsing
                IIncomingDataParser parser = null;
                DataSet rawData = null;
                try
                {
                    switch (rbSourceType.SelectedIndex)
                    {
                        case 0:
                            IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), ConfigurationManager.AppSettings["McOleDbServiceString"]);
                            rawData = helper.ConvertExcelToDataSet(Server.MapPath(hdnFilePath.Value));
                            break;
                        case 1:
                            parser = new XmlIncomingDataParser();
                            rawData = parser.Parse(Server.MapPath(hdnFilePath.Value), null);
                            break;
                        case 2:
                            rawData = GetRawDataForCSV();
                            break;
                    }
                }
                catch(Exception ex)
                {
                    CHelper.GenerateErrorReport(ex);
                    ViewState["ServiceError"] = true;
                    ViewState["ErrorFileName"] = Server.MapPath(hdnFilePath.Value);
                    ucWizard.MoveTo(this.step4);
                    return;
                }
                #endregion

                if (ViewState["lip"] != null && prevStepId == ucWizard.ActiveStep.ID)
                    lip = (ListImportParameters)ViewState["lip"];
                else if (rbNewList.Checked)
                {
                    lip = new ListImportParameters(int.Parse(destFolderId.Value), txtTitle.Text, rawData, 0);
                    lblName.Text = String.Format("<b>{0}:</b>&nbsp;&nbsp;{1}",
                        GetGlobalResourceObject("IbnFramework.ListInfo", "List").ToString(), txtTitle.Text);
                    lip.Status = int.Parse(ddStatus.SelectedValue);
                    lip.ListType = int.Parse(ddType.SelectedValue);
                }
                else
                {
                    foreach (DataGridItem dgi in dgLists.Items)
                    {
                        CheckBox cb = (CheckBox)dgi.FindControl("cbListItem");
                        if (cb != null && cb.Checked)
                        {
                            hdnListId.Value = dgi.Cells[0].Text;
                            break;
                        }
                    }
                    lip = new ListImportParameters(int.Parse(hdnListId.Value), rawData, 0);
                    ListInfo li = new ListInfo(int.Parse(hdnListId.Value));
                    lblName.Text = String.Format("<b>{0}:</b>&nbsp;&nbsp;{1}",
                        GetGlobalResourceObject("IbnFramework.ListInfo", "List").ToString(), li.Title);
                }

                ViewState["lip"] = lip;
                Session[_keyLIP] = lip;
                BindDG();

                AddMetaFieldLink();
            }

            if (ucWizard.ActiveStep.ID == "step4")
            {
                if (ViewState["ServiceError"] != null && (bool)ViewState["ServiceError"])
                {
                    string fileName = ViewState["ErrorFileName"].ToString();
                    if (fileName.EndsWith("xlsx") && !Is2007OfficeSystemDriverInstalled(fileName))
                        lblResult.Text = GetGlobalResourceObject("IbnFramework.ListInfo", "McOleDbServiceWarningXlsx").ToString();
                    else
                        lblResult.Text = GetGlobalResourceObject("IbnFramework.ListInfo", "McOleDbServiceWarning").ToString();
                }
                foreach (Control c in ucWizard.ActiveStep.Controls)
                {
                    if (c is Button)
                    {
                        Button btn = (Button)c;
                        string script = Mediachase.Ibn.Web.UI.WebControls.CommandHandler.GetCloseOpenedWindowScript(this.Page, String.Empty);
                        script += "return false;";
                        btn.OnClientClick = script;
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the ddCSV control.
        /// Parse and return LIP for CSV file
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void ddCSV_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataSet rawData = GetRawDataForCSV();
            if (rbNewList.Checked)
                lip = new ListImportParameters(int.Parse(destFolderId.Value), txtTitle.Text, rawData, 0);
            else
                lip = new ListImportParameters(int.Parse(hdnListId.Value), rawData, 0);

            ViewState["lip"] = lip;
            Session[_keyLIP] = lip;
            BindDG();
        }
Esempio n. 6
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            //After new field added need to update Lip
            if (CHelper.GetFromContext("NeedToChangeDataSource") != null && (bool)CHelper.GetFromContext("NeedToChangeDataSource"))
            {
                //lip = (ListImportParameters)CHelper.GetFromContext(_keyLIP);
                lip = (ListImportParameters)Session[_keyLIP];
                ViewState["lip"] = lip;
                Session[_keyLIP] = lip;
                FillDefaultValues(dgMapping, null);
                BindDG();
            }

            DefineHeaderTexts();
            if (ucWizard.ActiveStep.ID == "step2")
            {
                fsNewList.Visible = rbNewList.Checked;
                fsUpdateList.Visible = rbUpdList.Checked;
                tdLists.Visible = rbUpdList.Checked;

                MoveTree.AutoPostBackOnSelect = rbUpdList.Checked;
            }

            ucWizard.StepStyle.CssClass = (ucWizard.ActiveStep.ID == "step4") ? "" : "wizardStep";
        }
Esempio n. 7
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the ddi control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void ddi_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ViewState["lip"] != null)
            {
                lip = (ListImportParameters)ViewState["lip"];
                DropDownList ddl = (DropDownList)sender;
                DataGridItem dgi = (DataGridItem)ddl.NamingContainer;

                DataGrid dg = (DataGrid)dgi.NamingContainer;
                FillDefaultValues(dg, dgi);

                string mf = dgi.Cells[0].Text;

                switch (ddl.SelectedValue)
                {
                    case "-1":
                        lip.RemoveRuleByMetaField(mf);
                        break;
                    case "0":
                        MappingRule mr = lip.AssignDefaultValueRule(mf);
                        MetaField field = lip.GetDestinationMetaField(mf);
                        if (field.IsEnum)
                        {
                            DropDownList dd = (DropDownList)dgi.FindControl("ddColumn");
                            CHelper.SafeSelect(dd, mr.DefaultValue);
                        }
                        else
                        {
                            TextBox txt = (TextBox)dgi.FindControl("tbColumn");
                            if (txt != null)
                                txt.Text = mr.DefaultValue;
                        }
                        Label lbl = (Label)dgi.FindControl("lblColumn");
                        if (lbl != null)
                            lbl.Text = mr.DefaultValue;
                        break;
                    default:
                        lip.AssignCopyValueRule(ddl.SelectedValue, mf);
                        break;
                }

                ViewState["lip"] = lip;
                Session[_keyLIP] = lip;
                BindDG();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Handles the FinishButtonClick event of the ucWizard control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.WizardNavigationEventArgs"/> instance containing the event data.</param>
        void ucWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            if (ViewState["lip"] != null)
            {
                lip = (ListImportParameters)ViewState["lip"];
                FillDefaultValues(dgMapping, null);
                MappingError[] mas = ListManager.Import(lip);
                if (mas.Length == 0)
                    lblResult.Text = GetGlobalResourceObject("IbnFramework.ListInfo", "tImportWasSuccessfull").ToString();
                else
                {
                    ViewState["ErrorLog"] = ListManager.GetErrorLog(mas);
                    string sAction = String.Format("<a href=\"{1};\">{0}</a>",
                        GetGlobalResourceObject("IbnFramework.ListInfo", "tErrorList").ToString(),
                        this.Page.ClientScript.GetPostBackClientHyperlink(lbErrorLog, ""));

                    lblResult.Text = String.Format(
                        GetGlobalResourceObject("IbnFramework.ListInfo", "tImportWithErrors").ToString(),
                            sAction);
                }
                string cmd = String.Empty;
                if (Request["CommandName"] != null)
                {
                    CommandParameters cp = new CommandParameters(Request["CommandName"]);
                    cmd = cp.ToString();
                }
                Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterRefreshParentWindowScript(this.Page, cmd);
            }
        }
Esempio n. 9
0
        public long CreateListFromExcel(string excelPath, string SheetName, string title, string description, int folderId, int typeId, int statusId, int[] listCategory, string[] filter, bool ignoreErrors)
        {
            int listId = -1;

            try
            {
                if (errMsg == null)
                    errMsg = new ErrMsg();
                errMsg.DidUnderstand = true;
                Authenticate();

                ArrayList alCategories = new ArrayList(listCategory);
                ArrayList alFilter = new ArrayList(filter);

                using (TransactionScope tran = DataContext.Current.BeginTransaction())
                {
                    //listId = WebServicesHelper.CreateAndFillList(excelPath, SheetName, title, description, folderId, typeId, statusId, alCategories, alFilter, ignoreErrors);
                    //DataSet externalData = null;

                    IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), ConfigurationManager.AppSettings["McOleDbServiceString"]);
                    DataSet externalData = helper.ConvertExcelToDataSet(excelPath);

                    ListImportParameters param = new ListImportParameters(folderId, title, externalData, externalData.Tables.IndexOf(SheetName));
                    param.Description = description;

                    MappingError[] errors = ListManager.Import(param);

                    // OZ 2009-01-27 Update retval value
                    if(param.CreatedListId.HasValue)
                        listId = param.CreatedListId.Value;

                    tran.Commit();
                }

                errMsg.msg = "OK";
            }
            catch (UserNotAuthenticatedException)
            {
                errMsg.msg = "Your login or password is invalid.";
            }
            catch (Exception ex)
            {
                //errMsg.msg = ex.Message;
                errMsg.msg = ex.ToString();
            }
            return listId;
        }