 |
|
ช่วยหน่อยคับ ปวดหัีวมากเลยคับ แยกแต่ละ บริษัท ออกจากัน ใน DatagridView แล้วนับว่ามีแต่ละบริษัทมัจำนวนเท่าไหร |
|
 |
|
|
 |
 |
|
ช่วยตอบที่นะคับๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆๆ     
|
 |
 |
 |
 |
Date :
2011-09-01 11:15:32 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใน GridView เรียก OnRowDataBound="GridView_RowDataBound" หรือเปล่าครับ?
|
ประวัติการแก้ไข 2011-09-01 12:04:57 2011-09-01 12:13:08
 |
 |
 |
 |
Date :
2011-09-01 12:01:21 |
By :
Marcuz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไมได้เรียกคับ
|
 |
 |
 |
 |
Date :
2011-09-01 12:46:01 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
...
|
ประวัติการแก้ไข 2011-09-01 14:22:31
 |
 |
 |
 |
Date :
2011-09-01 12:54:28 |
By :
Marcuz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอจะมีวิธีไหนบ้างคับช่วยบอกหน่อยคับ ปวดหัวมา อาทิตหนึงแล้วคับ ไปไม่ถึงไหนเลยคับ ขอบคุณลวงหน้านะคับ
|
 |
 |
 |
 |
Date :
2011-09-01 13:13:57 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ไม่รู้จะเขียนโคดยังไง
|
 |
 |
 |
 |
Date :
2011-09-01 14:17:55 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วทำไมไม่เอา sql ดึงข้อมูลออกมาแบบ group by แต่แรกล่ะครับ
|
 |
 |
 |
 |
Date :
2011-09-01 14:43:38 |
By :
phoenekia |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรงนี้เกิดจากคีข้อมูลเข้าไป
จะอธิบายยังไงไม่แน่ใจ
คือ คีรหัสเข้าไปแล้วจะดึงข้อมูลออกมา show
แต่ตัวที่ดึงมามันมีแค่ -บริษัท -รหัส -ราคาปาย -ราคาขาย -และรายละเอียด แต่ไม่มี -จ ำนวน และ -รวม
แต่ที่นี้ผมต้องการ เอา ยอดรวมของบริษัทเดียวกันมารวมกันคับ ผมงงเป็นไก่ตาแตก แล้วคับไม่รู้จะทำยังไง เข้าใ้ห้โจทร์มาแบบนี้
|
 |
 |
 |
 |
Date :
2011-09-01 15:53:15 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมขอตัวอย่าง โคด sql ดึงข้อมูลออกมาแบบ group by หน่อยเพื่อจะคิดออก ขอบคุณคับอิอิ
|
 |
 |
 |
 |
Date :
2011-09-01 15:55:50 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ DataTable เป็น DataSource
แล้วใช้ DataTable.Compute("","")
ลองดูครับ
http://authors.aspalliance.com/aspxtreme/sys/data/DataTableClassCompute.aspx
http://www.mindfiresolutions.com/DataTable-Compute-Method-628.php
http://msdn.microsoft.com/en-us/library/system.data.datatable.compute.aspx
|
 |
 |
 |
 |
Date :
2011-09-01 15:56:01 |
By :
่ำVC#.Net |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอจะเริ่มเห็นแสงสว่างบ้างแล้ว ขอบคุณมากคับ
|
 |
 |
 |
 |
Date :
2011-09-01 16:09:23 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอจะเห็นแสงนิดหนึงไม่ได้เลย ปันหาก็มาอีกแล้ว คือในตารางนี้ผมให้มันสามารถแก้ไขจำนวนได้คับ ผมรวมไม่คงที่
|
 |
 |
 |
 |
Date :
2011-09-01 16:13:49 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ฐานข้อมูลที่ดึงมา จะมีแค่นี้ ส่วนจำนวน จะเกิดจากตั้งค่าให้มันเป็น 1 และผลรวม เกิดจาก การเอา จำนวน * ราคาขาย
|
 |
 |
 |
 |
Date :
2011-09-01 16:25:13 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอเอามา โชร์เสร็จ แล้ว รวมเสร็จแล้ว ก็อยากให้มันรวมแยกบริษัท ว่าในตารางนี้ บริษัทนี้ รวมยอดทั้งหมดได้เท่าไหร และอีกบริษัท รวมยอดได้เทาไหร
|
 |
 |
 |
 |
Date :
2011-09-01 16:28:02 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าข้อมูลไม่มีในฐานข้อมูลก้สร้าง Control หรือ Event อะไรก็ได้ที่มันทำครั้งสุดท้ายก็จะโชว์ผลลัพธ์
ถ้าเป็นผมนะ ! ผมใช้ For วน if เช็คชื่อบริษัท เมื่อเข้าเงื่อนไข สร้างตัวแปรมารวมค่าในช่องรวม จากนั้นก็ นำค่าตัวแปรนั้นมาใส่ในTextbox
|
 |
 |
 |
 |
Date :
2011-09-01 16:53:12 |
By :
@teenee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอจะมีโคด ตัวอย่างให้ได้บ้างไหมคับ ขอบคุณมากๆๆๆๆๆๆๆๆๆๆๆๆๆๆ คับ
|
 |
 |
 |
 |
Date :
2011-09-01 16:57:13 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณเอาข้อมูลเข้า GridView ยังไงครับ?
Code (C#)
GridView.DataSource = ;
GridView.DataBind();
ไม่ได้ใช้ control อะไรเลยเหรอ
|
 |
 |
 |
 |
Date :
2011-09-01 17:06:51 |
By :
Marcuz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
sb.Remove(0, sb.Length);
sb.Append("select*from in_goods where fg_code='" + textBox3.Text + "'");
string sqlingoods = sb.ToString();
SqlDataReader dr;
DataTable dt;
com = new SqlCommand(); {
com.CommandType = CommandType.Text;
com.CommandText = sqlingoods;
com.Connection = con;
dr = com.ExecuteReader();
if (dr.HasRows)
{
string ou_code, fg_code, fg_name, u_price, old_price, amount = "1";
dt = new DataTable();
dt.Load(dr);
ou_code = dt.Rows[0]["ou_code"].ToString();
fg_code = dt.Rows[0]["fg_code"].ToString();
u_price = dt.Rows[0]["u_price"].ToString();
old_price = dt.Rows[0]["old_price"].ToString();
fg_name = dt.Rows[0]["fg_name"].ToString();
ตรงนี้คับ ----- > this.dataGridView1.Rows.Add(ou_code, fg_code, old_price, u_price, amount, null, fg_name);
textBox3.Clear();
tatolcell();
CalculateNet();
CalculateNet2();
}
else {
fmshowsale fmsal = new fmshowsale();
fmsal.ShowDialog();
textBox3.Text = fmsal.getID;
} dr.Close();
}
|
 |
 |
 |
 |
Date :
2011-09-01 17:14:36 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
3 ตัวนี้ ตัวที่รวม
Code (C#)
private void CalculateNet()
{
int i = 0;
double tmpNetTotal = 0;
for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
{
tmpNetTotal += Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value);
}
textBox4.Text = tmpNetTotal.ToString("#,##0");
}
private void CalculateNet2()
{
int i = 0;
double tmpNetTotal = 0;
for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
{
tmpNetTotal += Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value);
}
textBox5.Text = tmpNetTotal.ToString("#,##0.00");
}
private void tatolcell()
{
int i;
for (i = 0; i < dataGridView1.Rows.Count; i++)
{
double cell1 = Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value);
int cell2 = Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value);
this.dataGridView1.Rows[i].Cells[5].Value = cell1 * cell2;
}
}
|
 |
 |
 |
 |
Date :
2011-09-01 17:31:31 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ที่ต้องแยกบริษัทเพราะว่า เข้าต้องการแบงเงินกัน แต่เวลาขายขายด้วยกัน ใช้โปรแกรมตัวเดียว
|
 |
 |
 |
 |
Date :
2011-09-01 17:44:43 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีใครตอบผมเลย
|
 |
 |
 |
 |
Date :
2011-09-02 09:18:07 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมได้แล้วคับ ไม่รู้จะเขียนยังไง ผมเอาแบบนี้เลย อิอิ
Code (C#)
private void check() {
int i = 0;
double a = 0;
string tmpProductID;
for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
{
tmpProductID = dataGridView1.Rows[i].Cells[1].Value.ToString();
if (tmpProductID == "TG")
{
a+= Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value);
}
txtTG.Text = a.ToString();
}
}
private void check2()
{
int i = 0;
double a = 0;
string tmpProductID;
for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
{
tmpProductID = dataGridView1.Rows[i].Cells[1].Value.ToString();
if (tmpProductID == "FN")
{
a += Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value);
}
txtFN.Text = a.ToString();
}
}
private void check3()
{
int i = 0;
double a = 0;
string tmpProductID;
for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
{
tmpProductID = dataGridView1.Rows[i].Cells[1].Value.ToString();
if (tmpProductID == "GD")
{
a += Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value);
}
txtGd.Text = a.ToString();
}
}
|
 |
 |
 |
 |
Date :
2011-09-02 14:23:12 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ผลที่ได้
|
 |
 |
 |
 |
Date :
2011-09-02 14:32:10 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบรบก่อนอีกนะคับ อิอิ คือผมต้องการ ดึงข้อมูลที่มากที่สุด มา +1 โดยมี เลข 0 ข้างหน้า 5 ตัวคับ
ตัวอย่าง เช่น 00001 ทำไงคับ
แล้ว พอถึง 00009 ถ้าบวก 1 อีกจะเป็น 0000010 จะแก้ยังไงคับให้มันเป็น 00010
|
 |
 |
 |
 |
Date :
2011-09-02 15:32:16 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากคับๆ
|
 |
 |
 |
 |
Date :
2011-09-02 16:45:47 |
By :
ปองศัก |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
'เอาฟังก์ชั่นนี้ไปใช้ดูนะคับ
Code (VB.NET)
Public Function AutoNumID(ByVal _ID As String, ByVal _Table As String, ByVal _Format As String, ByVal _Begin As String) As String
Dim _GerID As String = "", lastID As Integer = 0
strData = "Select " & _ID & " From " & _Table & " Order By " & _ID & " desc"
Try
Com = New SqlCommand
With Com
.CommandType = CommandType.Text
.CommandText = strData
.Connection = Conn
dr = .ExecuteReader
dr.Read()
lastID = CInt(CStr(dr.Item("" & _ID & "")))
lastID = lastID + 1
_GerID = lastID.ToString("" & _Format & "")
End With
Catch ex As Exception
_GerID = "" & _Begin & ""
End Try
dr.Close()
AutoNumID = _GerID
End Function
'เขียน sub มาเรียกใช้งานในฟอร์มที่มีการเพิ่มข้อมูล
Code (VB.NET)
Public Sub AutoID()
txtprefixid.Text = AutoNumID("kindid", "kind", "00000", "000001")
End Sub
|
 |
 |
 |
 |
Date :
2011-09-09 09:37:11 |
By :
wikarn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|