コード例 #1
0
        /// <summary>
        /// </summary>
        void gvFields_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Guid fieldId;

            try
            {
                fieldId = new Guid(gvFields.Rows[e.RowIndex].Cells[0].Value.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: see status window below for details.", "ERROR");
                var msg = "Error retrieving field ID from gridview: " + ex.Message;
                GenUtil.LogIt(txtStatus, msg);
                return;
            }



            if (fdf != null)
            {
                fdf.Close();
            }

            fdf = new FieldDetailsForm();

            fdf.siteUrl = txtSiteUrl.Text.Trim(); // "http://localhost/"
            //fdf.webID = selListNode.Parent.Name; // "/"
            //fdf.webName = selListNode.Parent.Text; // "Root"
            fdf.listID   = selListNode.Name; // "guid"
            fdf.listName = selListNode.Text; // "States"
            fdf.fieldId  = fieldId;

            fdf.parentForm = this;

            fdf.Show();
        }
コード例 #2
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();
            }
        }