/// <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> {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> {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; } } } }
/// <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; } } } }
private void ShowStep(int step) { for (int i = 0; i <= _stepCount; i++) ((Panel)steps[i]).Visible = false; ((Panel)steps[step - 1]).Visible = true; #region Step 2 if (step == 2) { if (rbSourceObject.SelectedValue == "0") { lgdConnectInf.InnerText = LocRM.GetString("ConnectToAD"); tblADConnection.Visible = true; tblFileConnection.Visible = false; ChangedLdap(); tblFilter.Visible = true; } else { lgdConnectInf.InnerText = LocRM.GetString("tLoadToServer"); tblADConnection.Visible = false; tblFileConnection.Visible = true; ((WizardTemplate)Page.Controls[0]).btnNext.Attributes.Add("onclick", "ShowProgress();"); tblFilter.Visible = false; } ViewState["Fields"] = null; ViewState["ADFields"] = null; ViewState["ldapPassword"] = null; grdFields.EditItemIndex = -1; tbFilter.Text = ""; wwwPath.Value = ""; ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = false; } #endregion #region Step 3 if (step == 3) { if (ViewState["Fields"] == null || ViewState["Fields"].ToString().Length == 0) { DataTable dtFields = new DataTable(); dtFields.Columns.Add(new DataColumn("IBNField", typeof(string))); dtFields.Columns.Add(new DataColumn("IBNFieldDisplay", typeof(string))); dtFields.Columns.Add(new DataColumn("ADField", typeof(string))); dtFields.Columns.Add(new DataColumn("realADField", typeof(string))); DataRow dr1; string[] sarray = null; string[] alIBNFields = UserInfo.PropertyNamesIbn; if (rbSourceObject.SelectedValue == "0") { pc["ADDomain"] = txtDomain.Text; pc["ADUserName"] = txtUserName.Text; pc["ADLDAPSettings"] = ddLDAPSettings.SelectedValue; LdapSettings lsets = null; if (int.Parse(ddLDAPSettings.SelectedValue) > 0) lsets = LdapSettings.Load(int.Parse(ddLDAPSettings.SelectedValue)); else lsets = new Mediachase.IBN.Business.LdapSettings(); string sPassword = txtPassword.Text; if (txtDomain.Text == lsets.Domain && txtUserName.Text == lsets.Username && txtPassword.Text == "") sPassword = lsets.Password; ViewState["ldapPassword"] = sPassword; ActiveDirectory ad = new ActiveDirectory(txtDomain.Text, txtUserName.Text, sPassword, tbFilter.Text); tbFilter.Text = lsets.Filter; foreach (string name in alIBNFields) { dr1 = dtFields.NewRow(); dr1["IBNField"] = name; dr1["IBNFieldDisplay"] = Mediachase.Ibn.Web.UI.CHelper.GetResFileString(String.Format("{{IbnFramework.Common:{0}}}", name)); dr1["ADField"] = ad.FieldsMatch[name]; dr1["realADField"] = ad.FieldsMatch[name]; if (ddLDAPSettings.SelectedValue != "0") { foreach (LdapField lf in lsets.Fields) if (lf.IbnName == name) { dr1["ADField"] = lf.LdapName; dr1["realADField"] = lf.LdapName; break; } } dtFields.Rows.Add(dr1); } sarray = ad.GetProperties(); } else { if (fSourceFile.PostedFile != null && fSourceFile.PostedFile.ContentLength > 0) { ProcessFileCache(Server.MapPath(CommonHelper.ChartPath)); String dir = CommonHelper.ChartPath; string wwwpath = dir + Guid.NewGuid().ToString(); switch (rbSourceType.SelectedValue) { case "0": //wwwpath += ".xls"; // OZ: Added XLS and XLSX extensions wwwpath += Path.GetExtension(fSourceFile.PostedFile.FileName); break; case "1": wwwpath += ".xml"; break; default: break; } wwwPath.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(); } IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), System.Configuration.ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwpath)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } DataTable dtSource = rawData.Tables[0]; int i = 0; sarray = new string[dtSource.Columns.Count]; foreach (DataColumn dc in dtSource.Columns) { sarray[i++] = dc.ColumnName; } foreach (string name in alIBNFields) { dr1 = dtFields.NewRow(); dr1["IBNField"] = name; dr1["IBNFieldDisplay"] = Mediachase.Ibn.Web.UI.CHelper.GetResFileString(String.Format("{{IbnFramework.Common:{0}}}", name)); dr1["ADField"] = LocRM.GetString("tNotSet"); dr1["realADField"] = "0"; foreach (string str in sarray) if (String.Compare(str, name, true) == 0 || String.Compare(str, Mediachase.Ibn.Web.UI.CHelper.GetResFileString(String.Format("{{IbnFramework.Common:{0}}}", name)), true) == 0) { dr1["ADField"] = str; dr1["realADField"] = str; } dtFields.Rows.Add(dr1); } } else ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = true; } ViewState["Fields"] = dtFields; grdFields.DataSource = dtFields.DefaultView; grdFields.DataBind(); if (sarray != null) { string sValues = String.Join(",", sarray); ViewState["ADFields"] = sValues; } } else { BindDG(); } ViewState["Users"] = null; ViewState["FullUsers"] = null; } #endregion #region Step 4 if (step == 4) { grdFields.EditItemIndex = -1; DataView dv = null; if (ViewState["FullUsers"] == null || ViewState["FullUsers"].ToString().Length == 0) { string[] alIBNFields = UserInfo.PropertyNamesIbn; DataTable dtFields = (DataTable)ViewState["Fields"]; DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Add", typeof(bool))); dt.Columns.Add(new DataColumn("Weight", typeof(int))); dt.Columns.Add(new DataColumn("Login", typeof(string))); dt.Columns.Add(new DataColumn("FirstName", typeof(string))); dt.Columns.Add(new DataColumn("LastName", typeof(string))); dt.Columns.Add(new DataColumn("Email", typeof(string))); dt.Columns.Add(new DataColumn("Phone", typeof(string))); dt.Columns.Add(new DataColumn("Fax", typeof(string))); dt.Columns.Add(new DataColumn("Mobile", typeof(string))); dt.Columns.Add(new DataColumn("Company", typeof(string))); dt.Columns.Add(new DataColumn("JobTitle", typeof(string))); dt.Columns.Add(new DataColumn("Department", typeof(string))); dt.Columns.Add(new DataColumn("Location", typeof(string))); dt.Columns.Add(new DataColumn("BadLogin", typeof(bool))); dt.Columns.Add(new DataColumn("BadEmail", typeof(bool))); //dt.Columns.Add(new DataColumn("BadWinLogin", typeof(bool))); dt.Columns.Add(new DataColumn("IsBad", typeof(bool))); dt.Columns.Add(new DataColumn("IsBadGroup", typeof(bool))); dt.Columns.Add(new DataColumn("Groups", typeof(string))); dt.Columns.Add(new DataColumn("IMGroup", typeof(int))); dt.Columns.Add(new DataColumn("LdapUid", typeof(string))); dt.Columns.Add(new DataColumn("WindowsLogin", typeof(string))); DataRow dr; if (rbSourceObject.SelectedValue == "0") { string sPassword = ViewState["ldapPassword"].ToString(); if (String.IsNullOrEmpty(sPassword) && int.Parse(ddLDAPSettings.SelectedValue) > 0) { LdapSettings lsets = LdapSettings.Load(int.Parse(ddLDAPSettings.SelectedValue)); if (txtDomain.Text == lsets.Domain && txtUserName.Text == lsets.Username && txtPassword.Text == "") sPassword = lsets.Password; } ActiveDirectory ad = new ActiveDirectory(txtDomain.Text, txtUserName.Text, sPassword, tbFilter.Text); foreach (string s in alIBNFields) { DataRow[] drMas = dtFields.Select("IBNField = '" + s + "'"); if (drMas.Length > 0) { string ss = drMas[0]["realADField"].ToString(); if (ss != "0" && !ss.Equals(ad.FieldsMatch[s])) { ad.FieldsMatch[s] = ss; } } } ArrayList alUsers = ad.GetUsers(); foreach (UserInfo _ui in alUsers) { dr = dt.NewRow(); dr["Login"] = _ui.Login; dr["FirstName"] = _ui.FirstName; dr["LastName"] = _ui.LastName; dr["Email"] = _ui.Email; if (_ui.FirstName != "" && _ui.LastName != "" && _ui.Email != "") dr["Add"] = true; else dr["Add"] = false; if (_ui.FirstName != "" && _ui.LastName != "") dr["Weight"] = 0; else dr["Weight"] = 1; dr["Phone"] = _ui.Phone; dr["Fax"] = _ui.Fax; dr["Mobile"] = _ui.Mobile; dr["Company"] = _ui.Company; dr["JobTitle"] = _ui.JobTitle; dr["Department"] = _ui.Department; dr["Location"] = _ui.Location; dr["BadLogin"] = false; dr["BadEmail"] = false; //dr["BadWinLogin"] = false; dr["IsBad"] = false; dr["IsBadGroup"] = false; dr["Groups"] = ((int)InternalSecureGroups.ProjectManager).ToString() + ","; dr["IMGroup"] = -1; dr["LdapUid"] = _ui.LdapUid; dr["WindowsLogin"] = _ui.WindowsLogin; dt.Rows.Add(dr); } } else { IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: // [03.06.05] fix some problems with oledb and asp.net IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), System.Configuration.ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwPath.Value)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } DataTable dtSource = rawData.Tables[0]; string sValues = ViewState["ADFields"].ToString(); ArrayList alADFields = new ArrayList(sValues.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); int count = 1; foreach (DataRow drFile in dtSource.Rows) { dr = dt.NewRow(); dr["Add"] = true; dr["Weight"] = 0; dr["BadLogin"] = false; dr["BadEmail"] = false; //dr["BadWinLogin"] = false; dr["IsBad"] = false; dr["IsBadGroup"] = false; dr["Groups"] = ((int)InternalSecureGroups.ProjectManager).ToString() + ","; dr["IMGroup"] = -1; bool flLogin = false; foreach (string sname in alADFields) { DataRow[] drF = dtFields.Select("realADField = '" + sname + "'"); if (drF.Length > 0) { string ss = drF[0]["IBNField"].ToString(); if (ss == "Login") flLogin = true; dr[ss] = drFile[sname]; } } if (!flLogin) dr["Login"] = "******" + (count++).ToString(); dt.Rows.Add(dr); } } ViewState["Users"] = dt; DataTable dtFull = dt.Clone(); DataRow drNew; foreach (DataRow dr1 in dt.Rows) { drNew = dtFull.NewRow(); drNew.ItemArray = dr1.ItemArray; dtFull.Rows.Add(drNew); } ViewState["FullUsers"] = dtFull; dv = dt.DefaultView; } else dv = ((DataTable)ViewState["FullUsers"]).DefaultView; dv.Sort = "Weight, LastName, FirstName, Login"; dgUsers.DataSource = dv; dgUsers.DataBind(); ((WizardTemplate)Page.Controls[0]).btnNext.CausesValidation = true; ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = false; } #endregion #region Step 5 if (step == 5) { DataTable dt = (DataTable)ViewState["Users"]; DataTable dtFull = (DataTable)ViewState["FullUsers"]; string sExceptions = ""; foreach (DataGridItem item in dgUsers.Items) { foreach (Control control in item.Cells[0].Controls) { if (control is HtmlInputCheckBox) { HtmlInputCheckBox checkBox = (HtmlInputCheckBox)control; //*****Undo***** //string filterElement = "Login = '******'"; try { //DataRow[] dr = dt.Select(filterElement); //DataRow[] drF = dtFull.Select(filterElement); DataRow dr = GetRowIsEqual(dt, "Login", item.Cells[3].Text); DataRow drF = GetRowIsEqual(dtFull, "Login", item.Cells[3].Text); if (!checkBox.Checked) { //if (dr.Length > 0) // dt.Rows.Remove(dr[0]); //if (drF.Length > 0) // drF[0]["Add"] = false; if (dr != null) dt.Rows.Remove(dr); if (drF != null) drF["Add"] = false; } else { //if (drF.Length > 0) // drF[0]["Add"] = true; //if (dr.Length == 0 && drF.Length > 0) //{ // DataRow drN = dt.NewRow(); // drN.ItemArray = drF[0].ItemArray; // dt.Rows.Add(drN); //} if (drF != null) drF["Add"] = true; if (dr == null && drF != null) { DataRow drN = dt.NewRow(); drN.ItemArray = drF.ItemArray; dt.Rows.Add(drN); } } } catch { sExceptions += item.Cells[3].Text + "\r\n"; } } } } foreach (DataRow bad in dt.Rows) { string sEmail = bad["Email"].ToString(); if (sEmail.Length == 0 || User.GetUserByEmail(sEmail) != -1) bad["BadEmail"] = true; string sLogin = bad["Login"].ToString(); if (sLogin.Length == 0 || User.GetUserByLogin(sLogin) != -1) bad["BadLogin"] = true; //string sWinLogin = bad["WindowsLogin"].ToString(); //if (sWinLogin.Length == 0 || User.GetUserByWindowsLogin(sWinLogin) != -1) // bad["BadWinLogin"] = true; if ((bool)bad["BadEmail"] || (bool)bad["BadLogin"]/* || (bool)bad["BadWinLogin"]*/) bad["IsBad"] = true; } ViewState["Users"] = dt; ViewState["UsersGroups"] = null; ViewState["FullUsers"] = dtFull; if (!String.IsNullOrEmpty(sExceptions)) Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), String.Format("alert('Bad Logins:\r\n{0}');", sExceptions), true); DataView dv = dt.DefaultView; dv.Sort = "IsBad DESC, Login"; dlUsers.DataSource = dv; dlUsers.DataBind(); dlUsers.SelectedIndex = 0; LinkButton lb = (LinkButton)dlUsers.Items[0].FindControl("lbUser"); if (lb != null) BinddgGroupsUsers(lb.CommandName); ((WizardTemplate)Page.Controls[0]).btnNext.CausesValidation = false; ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = false; } #endregion #region Step 6 if (step == 6) { ddIMGroups.DataTextField = "IMGroupName"; ddIMGroups.DataValueField = "IMGroupId"; ddIMGroups.DataSource = IMGroup.GetListIMGroupsWithoutPartners(); ddIMGroups.DataBind(); DataTable dt = (DataTable)ViewState["Users"]; DataTable dtFullOwn = dt.Clone(); DataRow drNew; foreach (DataRow dr1 in dt.Rows) { drNew = dtFullOwn.NewRow(); drNew.ItemArray = dr1.ItemArray; dtFullOwn.Rows.Add(drNew); } foreach (DataRow bad in dtFullOwn.Rows) { if ((bool)bad["IsBad"]) { string sLogin = bad["Login"].ToString(); #region *****Undo***** //DataRow[] dr = dt.Select("Login = '******'"); //if (dr.Length > 0) // dt.Rows.Remove(dr[0]); #endregion DataRow dr = GetRowIsEqual(dt, "Login", sLogin); if (dr != null) dt.Rows.Remove(dr); } } foreach (DataRow dr1 in dt.Rows) { dr1["IMGroup"] = int.Parse(ddIMGroups.SelectedValue); if (dr1["Groups"].ToString().Length < 2) dr1["IsBadGroup"] = true; } ViewState["UsersGroups"] = dt; DataView dv = dt.DefaultView; dv.Sort = "IsBadGroup DESC, LastName, FirstName"; dlUserGroups.DataSource = dv; dlUserGroups.DataBind(); if (dlUserGroups.Items.Count > 0) { dlUserGroups.SelectedIndex = 0; LinkButton lb = (LinkButton)dlUserGroups.Items[0].FindControl("lbUser2"); if (lb != null) BindGroups(lb.CommandName, true); btnSave2.Disabled = false; } else { ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = true; btnSave2.Disabled = true; } ((WizardTemplate)Page.Controls[0]).btnNext.CausesValidation = false; } #endregion #region Step 7 - Save if (step == 7) { DataTable dt = (DataTable)ViewState["UsersGroups"]; ArrayList alUsers = new ArrayList(); foreach (DataRow saverow in dt.Rows) { string sGroups = saverow["Groups"].ToString(); ArrayList alGroups = new ArrayList(); while (sGroups.Length > 0) { alGroups.Add(Int32.Parse(sGroups.Substring(0, sGroups.IndexOf(",")))); sGroups = sGroups.Remove(0, sGroups.IndexOf(",") + 1); } if (alGroups.Count > 0) { UserInfo _ui = new UserInfo(); _ui.Login = saverow["Login"].ToString(); _ui.FirstName = saverow["FirstName"].ToString(); _ui.LastName = saverow["LastName"].ToString(); _ui.Email = saverow["EMail"].ToString(); _ui.Phone = saverow["Phone"].ToString(); _ui.Fax = saverow["Fax"].ToString(); _ui.Mobile = saverow["Mobile"].ToString(); _ui.Company = saverow["Company"].ToString(); _ui.JobTitle = saverow["JobTitle"].ToString(); _ui.Department = saverow["Department"].ToString(); _ui.Location = saverow["Location"].ToString(); _ui.Groups = alGroups; _ui.ImGroupId = int.Parse(saverow["IMGroup"].ToString()); _ui.WindowsLogin = saverow["WindowsLogin"].ToString(); alUsers.Add(_ui); } } bool fl = false; if (alUsers.Count > 0) try { string password = "******"; if (!String.IsNullOrEmpty(txtCommonPassword.Text.Trim())) password = txtCommonPassword.Text.Trim(); User.CreateMultiple(alUsers, password, Security.CurrentUser.LanguageId); } catch { fl = true; } else fl = true; if (fl) lblError.Text = LocRM.GetString("tWereErrors"); else { foreach (UserInfo _ui in alUsers) { lblError.Text += CommonHelper.GetUserStatusUL(User.GetUserByLogin(_ui.Login)) + "<br>"; } } } #endregion }
private void ShowStep(int step) { for (int i = 0; i <= _stepCount + 1; i++) ((Panel)steps[i]).Visible = false; ((Panel)steps[step - 1]).Visible = true; //if(step==1) //{ // pastStep.Value="1"; //} #region step2 if (step == 2) { if (pastStep.Value == "1" && fSourceFile.PostedFile != null && fSourceFile.PostedFile.ContentLength > 0) { ProcessFileCache(Server.MapPath(CommonHelper.ChartPath)); String dir = CommonHelper.ChartPath; string wwwpath = dir + Guid.NewGuid().ToString(); switch (rbSourceType.SelectedValue) { case "0": //wwwpath += ".xls"; // OZ: Added XLS and XLSX extensions wwwpath += Path.GetExtension(fSourceFile.PostedFile.FileName); break; case "1": wwwpath += ".xml"; break; default: break; } wwwPath.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(); } IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwPath.Value)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } try { //rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); DataTable dtSource = rawData.Tables[0]; DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("SourceField", typeof(string))); dt.Columns.Add(new DataColumn("IBNField", typeof(string))); dt.Columns.Add(new DataColumn("realIBNFieldName", typeof(string))); dt.Columns.Add(new DataColumn("IsIn", typeof(bool))); DataRow dr; MappingMetaClass mc = null; mc = new IncidentMappingMetaClass(); foreach (ColumnInfo ci in mc.ColumnInfos) { dr = dt.NewRow(); dr["SourceField"] = LocRM.GetString("imNotSet"); if (ci.Field.IsSystem) { dr["IBNField"] = LocRM.GetString("tw" + ci.FieldName); dr["realIBNFieldName"] = ci.FieldName; } else { dr["IBNField"] = ci.FieldFriendlyName; dr["realIBNFieldName"] = ci.FieldName; } dr["IsIn"] = true; dt.Rows.Add(dr); } DataTable dtColumns = new DataTable(); dtColumns.Columns.Add(new DataColumn("SourceField", typeof(string))); dtColumns.Columns.Add(new DataColumn("IsIn", typeof(bool))); foreach (DataColumn dc in dtSource.Columns) { dr = dtColumns.NewRow(); dr["SourceField"] = dc.ColumnName; dr["IsIn"] = true; dtColumns.Rows.Add(dr); } ViewState["Fields"] = dt; ViewState["SourceFields"] = dtColumns; BindDG(); } catch { step2.Visible = false; step4.Visible = false; step5.Visible = false; step6.Visible = true; ((WizardTemplate)Page.Controls[0]).btnNext.Visible = false; ((WizardTemplate)Page.Controls[0]).btnBack.Visible = false; lblFinalResult.Text = String.Format(LocRM.GetString("imErrorListText"), String.Format("<a href='mailto:{0}'>{0}</a>", GlobalResourceManager.Strings["SupportEmail"])); return; } } ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = false; if (ViewState["Fields"] != null) BindDG(); else { ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = true; grdFields.DataSource = null; grdFields.DataBind(); } pastStep.Value = "2"; } #endregion #region step3 - not Lists if (step == 3) { DataTable dtFields = (DataTable)ViewState["Fields"]; IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwPath.Value)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } //DataSet rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); DataTable dtSource = rawData.Tables[0]; MappingMetaClass mc = null; mc = new IncidentMappingMetaClass(); MetaDataPlus.Import.Rule mapping = mc.CreateClassRule(); DataTable dtColumns = (DataTable)ViewState["SourceFields"]; foreach (DataRow dr in dtColumns.Rows) { string srcColumnName = dr["SourceField"].ToString(); DataColumn dc = dtSource.Columns[srcColumnName]; DataRow[] drF = dtFields.Select("SourceField = '" + srcColumnName + "'"); if (drF.Length > 0) { string realIBNField = drF[0]["realIBNFieldName"].ToString(); MetaField mf = mc.GetColumnInfo(realIBNField).Field; if (mf != null) { mapping.Add(new RuleItem(srcColumnName, dc.DataType, mf, FillTypes.CopyValue)); } } else mapping.Add(new RuleItem(srcColumnName, dc.DataType)); } try { FillResult fr = null; fr = ((IncidentMappingMetaClass)mc).FillData(FillDataMode.New, dtSource, mapping, 0); if (fr.ErrorRows > 0) { string sText = String.Format(LocRM.GetString("imSomeErrors"), fr.SuccessfulRows.ToString(), fr.ErrorRows.ToString()); int index = 0; foreach (string sError in fr.Errors) { if ((++index) > 5) break; else sText += "<br> <li>" + sError + "</li>"; } lblFirstResult.Text = sText; } else { lblFirstResult.Text = String.Format(LocRM.GetString("imWasDone"), fr.SuccessfulRows.ToString()); lblFinalResult.Text = String.Format(LocRM.GetString("imWasDone"), fr.SuccessfulRows.ToString()); ((WizardTemplate)Page.Controls[0]).btnNext.Visible = false; ((WizardTemplate)Page.Controls[0]).btnBack.Visible = false; //Page.RegisterStartupScript("onfourthload","<script language='javascript'>"+ //"NextStep();"+ //"function NextStep(){var obj = document.getElementById('"+((WizardTemplate)Page.Controls[0]).btnNext.ClientID+"'); obj.click();}</script>"); } } catch (Exception ex) { lblFirstResult.Text = LocRM.GetString("imSimpleError") + " " + ex.Message; } pastStep.Value = "3"; } #endregion #region step4 - not Lists if (step == 4) { DataTable dtFields = (DataTable)ViewState["Fields"]; IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwPath.Value)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } //DataSet rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); DataTable dtSource = rawData.Tables[0]; MappingMetaClass mc = null; mc = new IncidentMappingMetaClass(); MetaDataPlus.Import.Rule mapping = mc.CreateClassRule(); foreach (DataRow dr in dtFields.Rows) { string srcColumnName = dr["SourceField"].ToString(); DataColumn dc = dtSource.Columns[srcColumnName]; string realIBNField = dr["realIBNFieldName"].ToString(); if (realIBNField.Length > 0) { MetaField mf = mc.GetColumnInfo(realIBNField).Field; if (mf != null) { mapping.Add(new RuleItem(srcColumnName, dc.DataType, mf, FillTypes.CopyValue)); } } else mapping.Add(new RuleItem(srcColumnName, dc.DataType)); } try { FillResult fr = null; fr = ((IncidentMappingMetaClass)mc).FillData(FillDataMode.New, dtSource, mapping, -1); lblFinalResult.Text = String.Format(LocRM.GetString("imWasDone"), fr.SuccessfulRows.ToString()); } catch (Exception ex) { lblFinalResult.Text = LocRM.GetString("imSimpleError") + " " + ex.Message; } pastStep.Value = "5"; } #endregion }