Beispiel #1
0
        /// <summary>
        /// </summary>
        private void btnExportCode_Click(object sender, EventArgs e)
        {
            string q = GenUtil.SafeTrim(txtQuery.Text);

            q = q.Replace("\"", "\"\"");
            q = Regex.Replace(q, "( ){2,}", " ");
            q = GenUtil.RemoveWhiteSpace(q);
            q = Regex.Replace(q, "> <", "><");
            if (formChooser.appMode != Chooser.AppMode.UseSOM)
            {
                q = GenUtil.WrapWSQuery(q);
            }

            string v = GenUtil.SafeTrim(txtViewFields.Text);

            v = v.Replace("\"", "\"\"");
            v = Regex.Replace(v, "( ){2,}", " ");
            v = GenUtil.RemoveWhiteSpace(v);
            v = Regex.Replace(v, "> <", "><");

            string va = GenUtil.SafeTrim(txtViewAttributes.Text);

            va = va.Replace("\"", "\"\"");
            va = Regex.Replace(va, "( ){2,}", " ");
            va = GenUtil.RemoveWhiteSpace(va);
            va = Regex.Replace(va, "> <", "><");

            string rl = GenUtil.SafeToNum(txtRowLimit.Text).ToString();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format("string sQuery = @\"{0}\";", q));
            sb.AppendLine(string.Format("string sViewFields = @\"{0}\";", v));
            sb.AppendLine(string.Format("string sViewAttrs = @\"{0}\";", va));
            sb.AppendLine(string.Format("uint iRowLimit = {0};", rl));
            sb.AppendLine();

            sb.AppendLine("var oQuery = new SPQuery();");
            sb.AppendLine("oQuery.Query = sQuery;");
            sb.AppendLine("oQuery.ViewFields = sViewFields;");
            sb.AppendLine("oQuery.ViewAttributes = sViewAttrs;");
            sb.AppendLine("oQuery.RowLimit = iRowLimit;");
            sb.AppendLine();
            sb.AppendLine("SPListItemCollection collListItems = oList.GetItems(oQuery);");
            sb.AppendLine();
            sb.AppendLine("foreach (SPListItem oListItem in collListItems)");
            sb.AppendLine("{");
            sb.AppendLine("}");

            Clipboard.SetText(sb.ToString());

            MessageBox.Show("Generated C# Code Copied to Clipboard.");
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if ((rbUseWSCustCreds.Checked || rbUseWSOffice365.Checked) &&
                (GenUtil.IsNull(txtUsername.Text) || GenUtil.IsNull(txtPassword.Text)))
            {
                MessageBox.Show("Username and Password are required.", "ERROR");
                return;
            }

            if (rbUseSOM.Checked)
            {
                appMode = AppMode.UseWSCreds;
            }
            else if (rbUseWSCustCreds.Checked)
            {
                appMode = AppMode.UseWSCreds;
            }
            else if (rbUseWSImpers.Checked)
            {
                appMode = AppMode.UseWSDef;
            }
            else if (rbUseWSOffice365.Checked)
            {
                appMode = AppMode.UseWSOffice365;
            }

            credUsername = GenUtil.SafeTrim(txtUsername.Text);
            credPassword = GenUtil.SafeTrim(txtPassword.Text);
            credDomain   = GenUtil.SafeTrim(txtDomain.Text);

            if (form1 == null)
            {
                form1 = new Form1();
                form1.StartPosition = FormStartPosition.CenterScreen;
                form1.formChooser   = this;
            }

            form1.ShowHideListViews(rbUseSOM.Checked);

            this.Hide();
            form1.Show();
            form1.Activate();
        }
Beispiel #3
0
        /// <summary>
        /// </summary>
        private void SaveCurrentSessionInfo()
        {
            if (GenUtil.SafeToBool(ConfigurationManager.AppSettings["disableSession"]))
            {
                return;
            }

            StreamWriter sw = null;

            try
            {
                string iniPath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] { '\\' }) + "\\" + "session.ini";
                sw = new StreamWriter(iniPath, false);

                var sso = new SessionObject();
                sso.txtQuery          = GenUtil.NormalizeEol(txtQuery.Text);
                sso.txtRowLimit       = GenUtil.SafeTrim(txtRowLimit.Text);
                sso.txtSiteUrl        = GenUtil.SafeTrim(txtSiteUrl.Text);
                sso.txtViewAttributes = GenUtil.NormalizeEol(txtViewAttributes.Text);
                sso.txtViewFields     = GenUtil.NormalizeEol(txtViewFields.Text);

                sso.txtUsername = formChooser.credUsername;
                sso.txtPassword = formChooser.credPassword;
                sso.txtDomain   = formChooser.credDomain;

                sso.appMode = ((int)formChooser.appMode).ToString();

                var xml = XmlSerialization.Serialize(sso);

                sw.Write(xml);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Dispose();
                }
            }
        }
 /// <summary>
 /// </summary>
 public static string RemoveWhiteSpace(object s)
 {
     return(Regex.Replace(GenUtil.SafeTrim(s), "[\\t\\r\\n]", ""));
 }
Beispiel #5
0
        /// <summary>
        /// </summary>
        private void ExportGrid(DataGridView gv, string type)
        {
            var saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            saveFileDialog1.Filter           = "Csv file (*.csv)|*.csv|All Files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 1;
            saveFileDialog1.AddExtension     = true;
            saveFileDialog1.FileName         = "export.csv";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                toolStripStatusLabel1.Text = "Running...";
                statusStrip1.Refresh();

                picLogoWait.Visible = true;
                picLogoWait.Refresh();


                System.IO.StreamWriter streamWriter = null;

                try
                {
                    streamWriter = new System.IO.StreamWriter(saveFileDialog1.FileName);

                    string strHeader = "";

                    for (int i = 0; i < gv.Columns.Count; i++)
                    {
                        string curval = GenUtil.SafeTrim(gv.Columns[i].HeaderText);

                        if (curval.Contains(",") && !curval.StartsWith("\""))
                        {
                            strHeader += "\"" + curval + "\"" + ",";
                        }
                        else
                        {
                            strHeader += curval + ",";
                        }
                    }

                    streamWriter.WriteLine(strHeader);


                    for (int m = 0; m < gv.Rows.Count; m++)
                    {
                        string strRowValue = "";

                        for (int n = 0; n < gv.Columns.Count; n++)
                        {
                            string curval = GenUtil.SafeTrim(gv.Rows[m].Cells[n].Value);

                            if (curval.Contains(",") && !curval.StartsWith("\""))
                            {
                                strRowValue += "\"" + curval.Replace("\"", "'") + "\"" + ",";
                            }
                            else
                            {
                                strRowValue += curval.Replace("\"", "'") + ",";
                            }
                        }

                        streamWriter.WriteLine(strRowValue);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR: see status window below for details.", "ERROR");
                    GenUtil.LogIt(txtStatus, string.Format("ERROR: cannot export to CSV: {0}", ex.ToString()));
                }
                finally
                {
                    if (streamWriter != null)
                    {
                        streamWriter.Close();
                    }
                }

                toolStripStatusLabel1.Text = oldStatusText;
                statusStrip1.Refresh();
                picLogoWait.Visible = false;
                picLogoWait.Refresh();
            }
        }