/// <summary> /// 显示选择工作表的窗口 /// </summary> /// <param name="owner"></param> /// <param name="multiSelect">是否允许多选</param> /// <param name="selects">被选中的工作表索引</param> /// <returns></returns> public System.Windows.Forms.DialogResult ShowSelectWorksheet(System.Windows.Forms.IWin32Window owner, bool multiSelect, Core.ListDictionary <int> selects) { if (_excel == null) { return(System.Windows.Forms.DialogResult.Cancel); } #region wiondow code Core.GeneralForm gf = new GeneralForm(); System.Windows.Forms.ListView listView1; System.Windows.Forms.ColumnHeader columnHeader1; System.Windows.Forms.Button button1; System.Windows.Forms.Button button2; listView1 = new System.Windows.Forms.ListView(); columnHeader1 = new System.Windows.Forms.ColumnHeader(); button1 = new System.Windows.Forms.Button(); button2 = new System.Windows.Forms.Button(); gf.SuspendLayout(); // // listView1 // listView1.CheckBoxes = multiSelect; listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { columnHeader1 }); listView1.Location = new System.Drawing.Point(12, 12); listView1.Name = "listView1"; listView1.Size = new System.Drawing.Size(373, 253); listView1.TabIndex = 3; listView1.UseCompatibleStateImageBehavior = false; listView1.View = System.Windows.Forms.View.Details; // // columnHeader1 // columnHeader1.Text = "现存的工作表"; columnHeader1.Width = 260; // // button1 // button1.Location = new System.Drawing.Point(218, 278); button1.Name = "button1"; button1.Size = new System.Drawing.Size(75, 23); button1.TabIndex = 1; button1.Text = "确定"; button1.UseVisualStyleBackColor = true; button1.Click += delegate { if (multiSelect) { foreach (System.Windows.Forms.ListViewItem item in listView1.Items) { if (item.Checked) { selects.Add(item.Index + 1); } } } else { selects.Add(listView1.SelectedItems[0].Index + 1); } if (selects.Count <= 0) { System.Windows.Forms.MessageBox.Show(owner, "至少要选择一张工作表", "选择工作表", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); return; } gf.DialogResult = System.Windows.Forms.DialogResult.OK; }; // // button2 // button2.DialogResult = System.Windows.Forms.DialogResult.Cancel; button2.Location = new System.Drawing.Point(310, 278); button2.Name = "button2"; button2.Size = new System.Drawing.Size(75, 23); button2.TabIndex = 2; button2.Text = "取消"; button2.UseVisualStyleBackColor = true; button2.Click += delegate { gf.DialogResult = System.Windows.Forms.DialogResult.Cancel; gf.Close(); }; // // Form1 // gf.AcceptButton = button1; gf.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); gf.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; gf.CancelButton = button2; gf.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; gf.ClientSize = new System.Drawing.Size(400, 309); gf.Controls.Add(button2); gf.Controls.Add(button1); gf.Controls.Add(listView1); gf.MaximizeBox = false; gf.MinimizeBox = false; gf.Name = "Form1"; gf.ShowInTaskbar = false; gf.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; gf.Text = "现存的工作表"; gf.ResumeLayout(false); gf.Shown += delegate { for (int i = 1; i <= _excel.WorksheetCount; i++) { listView1.Items.Add(_excel.WorksheetName(i)); } }; #endregion return(gf.ShowDialog(owner)); }
private void DoListen() { try { if (listener == null) { listener = new TcpListener(ip, port); } listener.Start(); while (true) { if (listener == null) { break; } if (listener.Pending()) { _enRefresh = false; DataTansService client = new DataTansService(); client.Key = Guid.NewGuid().ToString(); TcpClient tcpClient = listener.AcceptTcpClient(); if (client.CreateLink(tcpClient)) { clientTables.Add(client.Key, client); if (!MustVerify) { client.Available = true; } Console.WriteLine("try Connect...{0},Count:{1}", client.Key, clientTables.Count.ToString()); clientTables[client.Key].Received += new TransEventHandler(client_Received); Console.WriteLine("try Connect1"); ////StreamWriter streamWriter = new StreamWriter(clientTables[client.Key].tcpClient.GetStream()); ////Console.WriteLine("try Connect2"); //byte[] buff = Encoding.Default.GetBytes(client.Key); //byte[] charBuff = new byte[buff.Length + 2]; //charBuff[0] = (byte)(TransTypeToChar(EnumTransDataType.校验)); ////char[] charBuff = new char[buff.Length * 2]; ////int i = Convert.ToBase64CharArray(buff, 0, buff.GetLength(0), charBuff, 1, Base64FormattingOptions.None); ////charBuff[0] = TransTypeToChar(EnumTransDataType.校验); //Array.Copy(buff, 0, charBuff, 1, buff.Length); //charBuff[charBuff.Length - 1] = (byte)'.';//添加结尾标记 ////Array.Resize<char>(ref charBuff, i + 2); //Console.WriteLine("try Connect2"); ////streamWriter.Write(charBuff); //clientTables[client.Key].tcpClient.GetStream().Write(charBuff, 0, charBuff.Length); //Console.WriteLine("try Connect3"); ////streamWriter.Flush(); ////Console.WriteLine("try Connect5"); //clientTables[client.Key].SendData(EnumTransDataType.校验, client.Key); } else { Console.WriteLine("CreateLink fail.{0},Count:{1}", client.Key, clientTables.Count.ToString()); } _enRefresh = true; } listenerThread.Join(100); } } catch (Exception ex) { Console.WriteLine(ex.Message); if (Log != null) { Log.Write(ex.Message); } } }