Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > select ข้อมูล reportList แสดงใน datagrid ครับ...................


 

[.NET] select ข้อมูล reportList แสดงใน datagrid ครับ...................

 
Topic : 123806



โพสกระทู้ ( 45 )
บทความ ( 0 )



สถานะออฟไลน์



1

2

Code (C#)
001.using System;
002.using System.Linq;
003.using System.Collections.Generic;
004.using System.ComponentModel;
005.using System.Data;
006.using System.Drawing;
007.using System.Text;
008.using System.Windows.Forms;
009.using System.IO;
010.using System.Configuration;
011.using System.Text.RegularExpressions;
012. 
013.namespace CheckStock1
014.{
015.    public partial class UNF : Form
016.    {
017.        public string A { get; set; }
018.        public string B { get; set; }
019.        public UNF(string data, string data2)
020.        {
021.            InitializeComponent();
022.            A = data;
023.            B = data2;
024.        }
025.        private void UNF_Load(object sender, EventArgs e)
026.        {
027.                DataGridTableStyle tabStyle = new DataGridTableStyle();
028.                tabStyle.MappingName = "UNF";
029. 
030.                DataGridTextBoxColumn col = new DataGridTextBoxColumn();
031.                col.MappingName = "U";
032.                col.HeaderText = "UNF";
033.                col.Width = 70;
034. 
035.                DataGridTextBoxColumn col1 = new DataGridTextBoxColumn();
036.                col1.MappingName = "A";
037.                col1.HeaderText = "Amount";
038.                col1.Width = 107;
039. 
040.                tabStyle.GridColumnStyles.Add(col);
041.                tabStyle.GridColumnStyles.Add(col1);
042. 
043.                this.dataGrid1.TableStyles.Clear();
044.                this.dataGrid1.TableStyles.Add(tabStyle);
045. 
046.                string log = "CheckStock.txt";
047.                StreamReader sr = new StreamReader(log);
048.                string[] columnnames = sr.ReadLine().Split('\t');
049.                DataTable dt = new DataTable("UNF");
050.                dt.Columns.Add("U");   
051.                dt.Columns.Add("A");
052.                foreach (string c in columnnames)
053.                {
054.                    dt.Columns.Add(c);
055.                }
056.                if (File.Exists(log) == false)
057.                {
058.                    return;
059.                }
060.                sr = new StreamReader(log);
061.                string line;
062.                List<ReportUNF> reportList = new List<ReportUNF>();
063.                ReportUNF reportUnf;
064.                string unf;
065.                string orderNo;
066.                string containerNo;
067.                while ((line = sr.ReadLine()) != null)
068.                {
069.                    int tab_target = line.Split('\t').Length - 2;
070. 
071.                    int indOfUnf = line.IndexOf(line.Substring(45,4));
072.                    unf = line.Substring(indOfUnf,4);
073. 
074.                    int indOfOrder = line.IndexOf(line.Substring(11, 10));
075.                    orderNo = line.Substring(indOfOrder, 10);
076. 
077.                    int indOfContainer = line.IndexOf(line.Substring(22, 11));
078.                    containerNo = line.Substring(indOfContainer, 11);
079. 
080.                    if (orderNo == A && containerNo == B)
081.                    {
082.                        if (reportList.Where(v => v.unf == unf).FirstOrDefault() != null)
083.                        {
084.                            foreach (var r in reportList.Where(v => v.unf == unf))
085.                            {
086.                                r.amount += 1;
087.                            }
088.                        }
089.                        else
090.                        {
091.                            reportUnf = new ReportUNF();
092.                            reportUnf.unf = unf;
093.                            reportUnf.amount += 1;
094.                            reportList.Add(reportUnf);
095.                        }
096.                    }
097.                }
098.                sr.Close();
099.                List<ReportUNF> reportAll = new List<ReportUNF>();
100.                this.dataGrid1.DataSource = dt;
101.            }
102.        private void btn_Menu_Click(object sender, EventArgs e)
103.        {
104.            Menu m1 = new Menu();
105.            m1.Show();
106.            this.Hide();    
107.        }
108.    }
109.    public class ReportUNF
110.    {
111.        public virtual string unf { get; set; }
112.        public virtual int amount { get; set; }
113.    }
114.}


ต้องการให้ข้อมูล reportList แสดงใน datagrid ครับ



Tag : .NET, C#, VS 2008 (.NET 3.x), Mobile

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-07-12 11:10:01 By : bankzbox1 View : 920 Reply : 7
 

 

No. 1



โพสกระทู้ ( 45 )
บทความ ( 0 )



สถานะออฟไลน์


ข้อมูลที่ต้องการอยู่บรรทัดที่ 94ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-07-12 11:11:31 By : bankzbox1
 

 

No. 2



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

dt.Columns.Add(c);

หมายความว่า ให้ dt Add Columns เรื่อย

แน่ใจว่าต้องการ Add Columns ไม่ใช่ Add Rows นะครับ

แน่นอนโค้ดที่ใช้ต้องต่างไป
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-07-12 11:19:34 By : lamaka.tor
 

 

No. 3



โพสกระทู้ ( 45 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : lamaka.tor เมื่อวันที่ 2016-07-12 11:19:34
รายละเอียดของการตอบ ::
เดี๋ยวลองปรับแก้ดูครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-07-12 11:27:40 By : bankzbox1
 

 

No. 4



โพสกระทู้ ( 535 )
บทความ ( 0 )



สถานะออฟไลน์


ผมก็ไม่เก่ง นะครับ แต่เท่าที่ดู code นายเอาข้อมูลจาก .txt ยัดเข้าไปใน reportUnf แล้วยังไม่ได้เอา ใส่ใน dt เลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-07-12 13:21:43 By : gaowteen
 

 

No. 5



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 4 เขียนโดย : gaowteen เมื่อวันที่ 2016-07-12 13:21:43
รายละเอียดของการตอบ ::
ใส่นะครับท่าน

แค่ดันใส่ผิด(อ้าว ดันบอกไปซัะงั้น 5555)

Code (C#)
01.DataTable dt = new DataTable("UNF");
02.               dt.Columns.Add("U");   
03.               dt.Columns.Add("A");
04.               foreach (string c in columnnames)
05.               {
06.                   dt.Columns.Add(c);//ความจริง ต้องเป็น Rows เพราะเป็นเช่นนั้น ท่านจะมี Columns ยาวไปไหนต่อไหนเลยละครับ
07.               }
08.               if (File.Exists(log) == false)
09.               {
10.                   return;
11.               }



ความจริงหลังจาก
Code (C#)
1.DataTable dt = new DataTable("UNF");
2.               dt.Columns.Add("U");   
3.               dt.Columns.Add("A");

น่าจะเป็นประมาณนี้ครับ
Code (C#)
01.for แต่ละ line
02.{
03.  for เพื่อแยกข้อความออกมา
04. {
05.    datarow r = dt.newrow;
06.   r("U")= ไอ้ตัวที่แยกมาน่านแหละ
07.   r("A")= ไอ้ตัวที่แยกมาน่านแหละ อีกอัน
08.   dt.Rows.Add(dr);
09. }
10.}


this.dataGrid1.DataSource = dt;//เอา dt มาใช้เลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-07-12 14:15:07 By : lamaka.tor
 

 

No. 6



โพสกระทู้ ( 45 )
บทความ ( 0 )



สถานะออฟไลน์


Code (C#)
001.using System;
002.using System.Linq;
003.using System.Collections.Generic;
004.using System.ComponentModel;
005.using System.Data;
006.using System.Drawing;
007.using System.Text;
008.using System.Windows.Forms;
009.using System.IO;
010.using System.Configuration;
011.using System.Text.RegularExpressions;
012. 
013.namespace CheckStock1
014.{
015.    public partial class UNF : Form
016.    {
017.        public string A { get; set; }
018.        public string B { get; set; }
019.        public UNF(string data, string data2)
020.        {
021.            InitializeComponent();
022.            A = data;
023.            B = data2;
024.        }
025.        private void UNF_Load(object sender, EventArgs e)
026.        {
027.            List<ReportUNF> reportList = new List<ReportUNF>();
028.            DataGridTableStyle tableS = new DataGridTableStyle();
029.            tableS.MappingName = reportList.GetType().Name;
030.            DataGridTextBoxColumn tbcName = new DataGridTextBoxColumn();
031.            tbcName.MappingName = "UNF";
032.            tbcName.HeaderText = "UNF";
033.            tbcName.Width = 74;
034.            tableS.GridColumnStyles.Add(tbcName);
035. 
036.            DataGridTableStyle tableS1 = new DataGridTableStyle();
037.            tableS.MappingName = reportList.GetType().Name;
038.            DataGridTextBoxColumn tbcName1 = new DataGridTextBoxColumn();
039.            tbcName1.MappingName = "AMOUNT";
040.            tbcName1.HeaderText = "AMOUNT";
041.            tbcName1.Width = 104;
042.            tableS.GridColumnStyles.Add(tbcName1);
043. 
044.            dataGrid1.TableStyles.Clear();
045.            dataGrid1.TableStyles.Add(tableS);
046.            dataGrid1.TableStyles.Add(tableS1);
047. 
048.                string log = "CheckStock.txt";
049.                StreamReader sr = new StreamReader(log);
050.                string[] row = sr.ReadLine().Split('\t');
051.                if (File.Exists(log) == false)
052.                {
053.                    return;
054.                }
055.                sr = new StreamReader(log);
056.                string line;
057.                ReportUNF reportUnf;
058.                string unf;
059.                string orderNo;
060.                string containerNo;
061.                while ((line = sr.ReadLine()) != null)
062.                {
063.                    int tab_target = line.Split('\t').Length - 2;
064. 
065.                    int indOfUnf = line.IndexOf(line.Substring(44,4));
066.                    unf = line.Substring(indOfUnf,4);
067. 
068.                    int indOfOrder = line.IndexOf(line.Substring(11, 10));
069.                    orderNo = line.Substring(indOfOrder, 10);
070. 
071.                    int indOfContainer = line.IndexOf(line.Substring(22, 11));
072.                    containerNo = line.Substring(indOfContainer, 11);
073. 
074.                    if (orderNo == A && containerNo == B)
075.                    {
076.                        if (reportList.Where(v => v.UNF == unf).FirstOrDefault() != null)
077.                        {
078.                            foreach (var r in reportList.Where(v => v.UNF == unf))
079.                            {
080.                                r.AMOUNT += 1;
081.                            }
082.                        }
083.                        else
084.                        {
085.                            reportUnf = new ReportUNF();
086.                            reportUnf.UNF = unf;
087.                            reportUnf.AMOUNT += 1;
088.                            reportList.Add(reportUnf);
089.                        }
090.                    }
091.                }
092.                sr.Close();
093.                this.dataGrid1.DataSource = reportList;
094.            }
095.        private void btn_Menu_Click(object sender, EventArgs e)
096.        {
097.            Menu m1 = new Menu();
098.            m1.Show();
099.            this.Hide();    
100.        }
101.    }
102.    public class ReportUNF
103.    {
104.        public virtual string UNF { get; set; }
105.        public virtual int AMOUNT { get; set; }
106.    }
107.}


เสร็จเรียบร้อยครับ ขอบคุนพี่ๆที่ไห้แนวทาง จบไปอีก 1 เดี๋ยวโปรเจคหน้าไห้พี่ๆช่วยใหม่ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-07-13 01:50:45 By : bankzbox1
 

 

No. 7



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

แหล่มครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-07-13 09:01:45 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : select ข้อมูล reportList แสดงใน datagrid ครับ...................
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่