/// <summary> /// Initializes the mapping document. /// </summary> /// <param name="context">The context.</param> protected override void InitializeMappingDocument(BusinessContext context) { InitializeMappingDocumentRequest request = ((InitializeMappingDocumentRequest)context.Request); MetaClass metaClass = DataContext.Current.GetMetaClass(context.GetTargetMetaClassName()); List <PrimaryKeyId> primaryKeyIds = new List <PrimaryKeyId>(); // Create Default Mapping MappingDocument retVal = new MappingDocument(); DataTable dataTable = request.Data.Tables[request.TableIndex]; MappingElement mapping = new MappingElement(dataTable.TableName, metaClass.Name); retVal.Add(mapping); MappingElementBuilder builder = new MappingElementBuilder(retVal); //Call creation mapping document by saved patterns DefaultMappingHelper.CreateMapingByPatternComparision(dataTable, metaClass, builder); // Write Response InitializeMappingDocumentResponse response = new InitializeMappingDocumentResponse(); response.MappingDocument = retVal; context.SetResponse(response); }
/// <summary> /// Handles the SelectedIndexChanged event of the ddCSV control. /// Parse and return IMDR 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(); InitializeMappingDocumentRequest imdr = new InitializeMappingDocumentRequest(_className, rawData, 0); InitializeMappingDocumentResponse resp = (InitializeMappingDocumentResponse)BusinessManager.Execute(imdr); MappingDocument md = resp.MappingDocument; ViewState["_ir"] = new ImportRequest(_className, rawData, md); BindDG(); }
/// <summary> /// Initializes the mapping document. /// </summary> /// <param name="context">The context.</param> protected override void InitializeMappingDocument(BusinessContext context) { InitializeMappingDocumentRequest request = ((InitializeMappingDocumentRequest)context.Request); MetaClass metaClass = DataContext.Current.GetMetaClass(context.GetTargetMetaClassName()); List<PrimaryKeyId> primaryKeyIds = new List<PrimaryKeyId>(); // Create Default Mapping MappingDocument retVal = new MappingDocument(); DataTable dataTable = request.Data.Tables[request.TableIndex]; MappingElement mapping = new MappingElement(dataTable.TableName, metaClass.Name); retVal.Add(mapping); MappingElementBuilder builder = new MappingElementBuilder(retVal); //Call creation mapping document by saved patterns DefaultMappingHelper.CreateMapingByPatternComparision(dataTable, metaClass, builder); // Write Response InitializeMappingDocumentResponse response = new InitializeMappingDocumentResponse(); response.MappingDocument = retVal; context.SetResponse(response); }
/// <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) { //step1 if (ucWizard.ActiveStep.ID == "step1") { ViewState["_ir"] = null; } //step2 if (ucWizard.ActiveStep.ID == "step3") { #region upload file if (fSourceFile.PostedFile != null && fSourceFile.PostedFile.ContentLength > 0) { 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 divCSV.Visible = (rbSourceType.SelectedIndex == 2); #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; case 3: rawData = VCardUtil.ConvertFile(Server.MapPath(hdnFilePath.Value)); break; } } catch (Exception ex) { CHelper.GenerateErrorReport(ex); ViewState["ServiceError"] = true; ViewState["ErrorFileName"] = Server.MapPath(hdnFilePath.Value); ucWizard.MoveTo(this.step4); return; } #endregion if (ViewState["_ir"] == null) { InitializeMappingDocumentRequest imdr = new InitializeMappingDocumentRequest(_className, rawData, 0); InitializeMappingDocumentResponse resp = (InitializeMappingDocumentResponse)BusinessManager.Execute(imdr); MappingDocument md = resp.MappingDocument; _ir = new ImportRequest(_className, rawData, md); ViewState["_ir"] = _ir; } BindDG(); } 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.Common", "McOleDbServiceWarningXlsx").ToString(); } else { lblResult.Text = GetGlobalResourceObject("IbnFramework.Common", "McOleDbServiceWarning").ToString(); } } foreach (Control c in ucWizard.ActiveStep.Controls) { if (c is Button) { Button btn = (Button)c; string param = String.Empty; if (!String.IsNullOrEmpty(_commandName)) { param = (new CommandParameters(_commandName)).ToString(); } string script = Mediachase.Ibn.Web.UI.WebControls.CommandHandler.GetCloseOpenedFrameScript(this.Page, param); script += " return false;"; btn.OnClientClick = script; } } } }