private void btnReportSale_Click(object sender, EventArgs e) { if (DrawId == null) { MessageBox.Show("กรุณาเลือกรายการก่อนค่ะ"); } else { Production.rptDrawProduction rpt = new rptDrawProduction(); rpt.StartPosition = FormStartPosition.CenterScreen; // กำหนด frm ย่อย ให้อยู่ตรงกลาง rpt.setDrawProductionHeadId = Convert.ToInt16(DrawId); rpt.ShowDialog(); } }
private void cmdExchange_Click(object sender, EventArgs e) { if (MessageBox.Show("คุณต้องการบันทึกรายการสั่งซื้อสินค้า ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { tr = Conn.BeginTransaction(); //SaleId(); try { string sqlSave; sb.Remove(0, sb.Length); sb.Append("UPDATE DRAW_PRODUCTION_HEAD "); sb.Append("SET DrawProductionHeadDate=@DrawProductionHeadDate,DrawProductionHeadDateTime=@DrawProductionHeadDateTime,"); sb.Append("DrawHand=@DrawHand,DrawRemark=@DrawRemark "); sb.Append("WHERE DrawProductionHeadId=@DrawProductionHeadId"); sb.Append(" DELETE FROM DRAW_PRODUCTION_DETAIL "); sb.Append("WHERE DrawProductionHeadId=@DrawProductionHeadId"); sb.Append(" DELETE FROM DRAW_PRODUCTION_WEIGHT "); sb.Append("WHERE DrawProductionHeadId=@DrawProductionHeadId"); sqlSave = sb.ToString(); com.Parameters.Clear(); com.Transaction = tr; com.CommandText = sqlSave; com.Parameters.Add("@DrawProductionHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblDrawProductionId.Text); com.Parameters.Add("@DrawProductionHeadDateTime", SqlDbType.DateTime).Value = dptDrawDate.Value.ToString("dd/MM/yyyy HH:mm:ss"); com.Parameters.Add("@DrawProductionHeadDate", SqlDbType.DateTime).Value = dptDrawDate.Value.ToString("dd/MM/yyyy"); com.Parameters.Add("@DrawHand", SqlDbType.NVarChar).Value = txtDrawId.Text.Trim(); com.Parameters.Add("@DrawRemark", SqlDbType.NVarChar).Value = rtbRemark.Text; com.ExecuteNonQuery(); //MessageBox.Show(sqlSave); for (int i = 0; i <= lsvProductList.Items.Count - 1; i++) { sb.Remove(0, sb.Length); sb.Append("INSERT INTO DRAW_PRODUCTION_DETAIL(DrawProductionHeadId,ProductId,DrawProductionDetailQuantityPack,DrawProductionDetailQuantity,DrawProductionAmountProduct)"); sb.Append(" VALUES(@DrawProductionHeadId,@ProductId,@DrawProductionDetailQuantityPack,@DrawProductionDetailQuantity,@DrawProductionAmountProduct)"); sqlSave = sb.ToString(); com.Parameters.Clear(); com.CommandText = sqlSave; com.Parameters.Add("@DrawProductionHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblDrawProductionId.Text); com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", ""); com.Parameters.Add("@DrawProductionDetailQuantityPack", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[8].Text.Replace(",", "")); com.Parameters.Add("@DrawProductionDetailQuantity", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[4].Text.Replace(",", "")).ToString("#,##0.00"); com.Parameters.Add("@DrawProductionAmountProduct", SqlDbType.Float).Value = Convert.ToSingle(lsvProductList.Items[i].SubItems[2].Text.Replace(",", "")); com.ExecuteNonQuery(); //MessageBox.Show(sqlSave); string weightext = lsvProductList.Items[i].SubItems[6].Text.ToString(); string[] weighttextarr = weightext.Split('#'); int len = weighttextarr.Length; string packtext = lsvProductList.Items[i].SubItems[7].Text.ToString(); string[] packtextarr = packtext.Split('#'); int lenpack = packtextarr.Length; if (weightext != "" && packtext != "") { for (int j = 0; j < weighttextarr.Length - 1; j++) { sb.Remove(0, sb.Length); sb.Append("INSERT INTO DRAW_PRODUCTION_WEIGHT (DrawProductionHeadId,ProductId,DrawProductionWeight,DrawProductionPack)"); sb.Append(" VALUES(@DrawProductionHeadId,@ProductId,@DrawProductionWeight,@DrawProductionPack)"); sqlSave = sb.ToString(); com.Parameters.Clear(); com.CommandText = sqlSave; com.Parameters.Add("@DrawProductionHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblDrawProductionId.Text); com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", ""); com.Parameters.Add("@DrawProductionWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString()).ToString("#,##0.00"); com.Parameters.Add("@DrawProductionPack", SqlDbType.Float).Value = Convert.ToSingle(packtextarr[j].ToString()); com.ExecuteNonQuery(); //MessageBox.Show(sqlSave); } } else if (weightext != "" && packtext == "") { // MessageBox.Show("case 2"); for (int j = 0; j < weighttextarr.Length - 1; j++) { sb.Remove(0, sb.Length); sb.Append("INSERT INTO DRAW_PRODUCTION_WEIGHT (DrawProductionHeadId,ProductId,DrawProductionWeight)"); sb.Append(" VALUES(@DrawProductionHeadId,@ProductId,@DrawProductionWeight)"); sqlSave = sb.ToString(); com.Parameters.Clear(); com.CommandText = sqlSave; com.Parameters.Add("@DrawProductionHeadId", SqlDbType.Int).Value = Convert.ToInt16(lblDrawProductionId.Text); com.Parameters.Add("@ProductId", SqlDbType.NVarChar).Value = lsvProductList.Items[i].SubItems[0].Text.Replace(",", ""); com.Parameters.Add("@DrawProductionWeight", SqlDbType.Float).Value = Convert.ToSingle(weighttextarr[j].ToString()).ToString("#,##0.00"); com.ExecuteNonQuery(); //MessageBox.Show(sqlSave); } } } tr.Commit(); // ต้องการ print หรือไม่ DialogResult dlg = MessageBox.Show("ต้องการพิมพ์รายงานหรือไม่ !!!", "ผลการทำงาน", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dlg == DialogResult.OK) { Production.rptDrawProduction rpt = new rptDrawProduction(); rpt.StartPosition = FormStartPosition.CenterScreen; // กำหนด frm ย่อย ให้อยู่ตรงกลาง rpt.setDrawProductionHeadId = Convert.ToInt16(lblDrawProductionId.Text.Trim()); rpt.ShowDialog(); } Close(); } catch (Exception ex) { MessageBox.Show("ไม่สามารถบันทึกรายการสั่งซื้อได้ เนื่องจาก " + ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning); //cmdSave.Focus(); tr.Rollback(); } } // pnlSelect.Visible = false; }