private void addButton_Click(object sender, EventArgs e) { DateTime datatime = DateTime.Now; String reciveOrderId = $"G{(DatabaseInstance.ReciveOrderTable.Count + 1).ToString("00000")}"; try { reciveOrder = new ReciveOrder { ReciveOrderId = reciveOrderId, ShopId = shopComboBox.Text, PigeonId = pigeonComboBox.Text, SalesOfficeId = "B001", EmployeeId = "E00001", Date = datatime.ToString(), ReceiptCheck = false }; DatabaseInstance.ReciveOrderTable.Insert(reciveOrder); DatabaseInstance.ReciveOrderTable.Sync(); try { reciveOrderDetail = new ReciveOrderDetail { ReciveOrderDetailId = $"GD{(DatabaseInstance.ReciveOrderDetailTable.Count + 1).ToString("00000")}", ReciveOrderId = reciveOrderId, ProductId = "PD00001", Quantity = int.Parse(amountTextBox.Text) }; DatabaseInstance.ReciveOrderDetailTable.Insert(reciveOrderDetail); DatabaseInstance.ReciveOrderDetailTable.Sync(); } catch { } } catch { MessageBox.Show("受注の登録に失敗しました"); } DriveInfo[] drives = DriveInfo.GetDrives(); foreach (DriveInfo item in drives) { } StreamWriter sw = File.CreateText("受注.txt"); string json = @"{""ReciveOrder"":"; using (var stream = new MemoryStream()) using (var sr = new StreamReader(stream)) { var serializer = new DataContractJsonSerializer(typeof(ReciveOrder)); serializer.WriteObject(stream, reciveOrder); stream.Position = 0; json += sr.ReadToEnd(); } using (var stream = new MemoryStream()) using (var sr = new StreamReader(stream)) { json += @",""ReciveOrderDetail"":"; var serializer = new DataContractJsonSerializer(typeof(ReciveOrderDetail)); serializer.WriteObject(stream, reciveOrderDetail); stream.Position = 0; json += sr.ReadToEnd(); } json += "}"; dynamic parsedJson = JsonConvert.DeserializeObject(json); sw.Write(JsonConvert.SerializeObject(parsedJson, Formatting.Indented)); sw.Close(); File.AppendAllText("test.txt", "a"); }
public IList<ReciveOrderDetail> getReciveOrderDetailByReciveCode(string _code) { IList<ReciveOrderDetail> reciveOrderDetails = new List<ReciveOrderDetail>(); ReciveOrderDetail reciveOrderDetail = null; try { Conn = db.openConnAccess(); sb = new StringBuilder(); sb.Remove(0, sb.Length); sb.Append(" SELECT ID,ReciveOrderCode,PCode,Cost,Number FROM tbReciveOrderDetail "); sb.Append(" WHERE (ReciveOrderCode ='" + _code + "')"); string sql; sql = sb.ToString(); com = new OleDbCommand(); com.CommandText = sql; com.CommandType = CommandType.Text; com.Connection = Conn; dr = com.ExecuteReader(); if (dr.HasRows) { DataTable dt = new DataTable(); dt.Load(dr); int index = 1; foreach (DataRow drw in dt.Rows) { reciveOrderDetail = new ReciveOrderDetail(); reciveOrderDetail.ID = Convert.ToInt32(drw["ID"].ToString()); reciveOrderDetail.Index = Convert.ToString(index); reciveOrderDetail.ReciveCode = drw["ReciveOrderCode"].ToString(); reciveOrderDetail.PCode= drw["PCode"].ToString(); Product product = serviceProduct.getByCode(drw["PCode"].ToString()); reciveOrderDetail.PName = product.PName; reciveOrderDetail.Cost =Convert.ToDouble(drw["Cost"].ToString()); reciveOrderDetail.NumberRecive = Convert.ToInt32(drw["NumberRecive"].ToString()); reciveOrderDetails.Add(reciveOrderDetail); index++; } } dr.Close(); } catch (Exception ex) { dr.Close(); Conn.Close(); return null; throw ex; } finally { Conn.Close(); } return reciveOrderDetails; }
private void cmdSave_Click(object sender, EventArgs e) { if (txtSearchSupiler.Text.Trim() == "") { MessageBox.Show("กรุณากรอกรหัสผู้จัดจำหน่ายด้วย !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSearchSupiler.Focus(); return; } int count = lsvProductList.Items.Count; if (count == 0) { MessageBox.Show("กรุณาเลือกสินค้าด้วย !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSearchProduct.Focus(); return; } if (MessageBox.Show("คุณต้องการเพิ่มการรับสินค้าใหม่ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { try { ReciveOrder reciveOrder = serviceReciveOrder.getByReciveCode(txtPR.Text.Trim()); if (reciveOrder == null) { ReciveOrder newReciveOrder = new ReciveOrder(); newReciveOrder.ReciveCode = txtPR.Text.Trim(); newReciveOrder.DateRecive = dtpRecive.Value; newReciveOrder.PO = txtPO.Text.Trim(); newReciveOrder.SPCode = txtSearchSupiler.Text.Trim(); newReciveOrder.SPName = txtSupilerName.Text.Trim(); newReciveOrder.NetDc = Convert.ToDouble(lblNetDC.Text.Trim()); newReciveOrder.NetVat = Convert.ToDouble(lblNetVAT.Text.Trim()); newReciveOrder.Net = Convert.ToDouble(lblNet.Text.Trim()); IList<ReciveOrderDetail> _reciveOrderDetails = new List<ReciveOrderDetail>(); ReciveOrderDetail _reciveOrderDetail; int j = 1; for (int i = 0; i <= lsvProductList.Items.Count - 1; i++) { _reciveOrderDetail =new ReciveOrderDetail(); _reciveOrderDetail.Index = Convert.ToString(j); _reciveOrderDetail.ReciveCode=txtPR.Text.Trim(); _reciveOrderDetail.PCode = lsvProductList.Items[i].SubItems[0].Text.Replace(",", ""); _reciveOrderDetail.PName = lsvProductList.Items[i].SubItems[1].Text.Replace(",", ""); _reciveOrderDetail.Cost =Convert.ToDouble(lsvProductList.Items[i].SubItems[2].Text.Replace(",", "")); _reciveOrderDetail.NumberRecive = Convert.ToInt32(lsvProductList.Items[i].SubItems[3].Text.Replace(",", "")); _reciveOrderDetail.Total = Convert.ToDouble(lsvProductList.Items[i].SubItems[4].Text.Replace(",", "")); _reciveOrderDetails.Add(_reciveOrderDetail); j++; } newReciveOrder.reciveOrderDetails = _reciveOrderDetails; bool save = serviceReciveOrder.Save(newReciveOrder,cboWarehouse.SelectedValue.ToString()); if (save) { MessageBox.Show("เพิ่มการรับสินค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearNet(); ClearProduct(); txtPO.Text = ""; lsvProductList.Items.Clear(); txtSearchProduct.Focus(); ClearSupiler(); txtPR.Text = serviceReciveOrder.getReciveCode(); } else { MessageBox.Show("ไม่สามารถ เพิ่มการรับสินค้าใหม่ได้!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("มีการรับสินค้านี้อยู่แล้ว!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("ไม่สามารถ เพิ่มการรับสินค้าได้ เนื่องจาก !!! : " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }