PageRenderTime 124ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/GreenChem/FORM/PURCHASING/frmEditPOtoSupplierExpedisi.cs

https://gitlab.com/juldhais/greenchem
C# | 213 lines | 186 code | 26 blank | 1 comment | 24 complexity | a0634c64c308d0195535e9a2ab0fb924 MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using System.Windows.Forms;
  4. using DevExpress.XtraEditors;
  5. using JulFunctions;
  6. namespace GreenChem.MenuTransaction
  7. {
  8. public partial class frmEditPOtoSupplierExpedisi : DevExpress.XtraEditors.XtraForm
  9. {
  10. int _id;
  11. GreenChemDataContext db;
  12. public frmEditPOtoSupplierExpedisi(int id)
  13. {
  14. InitializeComponent();
  15. _id = id;
  16. db = new GreenChemDataContext();
  17. RefreshSupplier();
  18. var po = db.POtoSupplierExpedisis.First(x => x.id == _id);
  19. txtNomorPO.Text = po.NomorPO;
  20. cmbDate.DateTime = po.Date;
  21. txtJatuhTempo.Text = po.JatuhTempo;
  22. txtDONumber.Text = po.DONumber;
  23. cmbTo.Text = po.Untuk;
  24. txtAddress.Text = po.Address;
  25. txtPIC.Text = po.PIC;
  26. txtPhone.Text = po.Phone;
  27. txtSendTo.Text = po.SendTo;
  28. txtSendToAddress.Text = po.SendToAddress;
  29. if (po.Transportation.Contains("[Kapal Cepat]")) chkKapalCepat.Checked = true;
  30. if (po.Transportation.Contains("[Kapal Lamat]")) chkKapalLambat.Checked = true;
  31. if (po.Transportation.Contains("[Trucking]")) chkTrucking.Checked = true;
  32. if (po.Transportation.Contains("[Lain-Lain]")) chkLainLain.Checked = true;
  33. txtVehicle.Text = po.Vehicle;
  34. txtTotalNilaiBarang.EditValue = po.Subtotal;
  35. txtTotalBeratDimensi.EditValue = po.BeratDimensi;
  36. txtUnitPrice.EditValue = po.UnitPrice;
  37. txtTotalBiayaExpedisi.EditValue = po.TotalBiayaExpedisi;
  38. txtTaxPercent.EditValue = po.PPNPercent;
  39. txtTax.EditValue = po.PPNAmount;
  40. txtAsuransiPercent.EditValue = po.AsuransiPercent;
  41. txtAsuransi.EditValue = po.AsuransiAmount;
  42. txtBiayaPalletized.EditValue = po.BiayaPalletized;
  43. txtBiayaHandlingIn.EditValue = po.BiayaHandlingIn;
  44. txtTotal.EditValue = po.Total;
  45. CalculateTotal(null, null);
  46. foreach (var item in po.DetailPOtoSupplierExpedisis)
  47. {
  48. DetailPOtoSupplierExpedisi detail = new DetailPOtoSupplierExpedisi();
  49. detail.NamaBarang = item.NamaBarang;
  50. detail.NilaiBarang = item.NilaiBarang;
  51. detail.BeratDimensi = item.BeratDimensi;
  52. detailPOtoSupplierExpedisiBindingSource.Add(detail);
  53. }
  54. gridControl.RefreshDataSource();
  55. }
  56. private void RefreshSupplier()
  57. {
  58. cmbTo.Properties.Items.Clear();
  59. var suppliers = from x in db.Suppliers
  60. where x.Active == true
  61. orderby x.Name
  62. select x.Name;
  63. foreach (var item in suppliers)
  64. cmbTo.Properties.Items.Add(item);
  65. }
  66. private void lblRefresh_Click(object sender, EventArgs e)
  67. {
  68. try
  69. {
  70. db = new GreenChemDataContext();
  71. cmbDate.DateTime = db.GetServerDate();
  72. RefreshSupplier();
  73. CalculateTotal(null, null);
  74. }
  75. catch { }
  76. }
  77. private void btnSave_Click(object sender, EventArgs e)
  78. {
  79. if (!chkKapalCepat.Checked && !chkKapalLambat.Checked && !chkTrucking.Checked && !chkLainLain.Checked)
  80. {
  81. XtraMessageBox.Show("Transportation must be choosen at least one.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  82. return;
  83. }
  84. try
  85. {
  86. Cursor.Current = Cursors.WaitCursor;
  87. db = new GreenChemDataContext();
  88. POtoSupplierExpedisi po = db.POtoSupplierExpedisis.First(x => x.id == _id);
  89. po.idUserAccount = frmUtama._iduseraccount;
  90. po.NomorPO = txtNomorPO.Text;
  91. po.Date = cmbDate.DateTime;
  92. po.JatuhTempo = txtJatuhTempo.Text;
  93. po.DONumber = txtDONumber.Text;
  94. po.Untuk = cmbTo.Text;
  95. po.Address = txtAddress.Text;
  96. po.PIC = txtPIC.Text;
  97. po.Phone = txtPhone.Text;
  98. po.SendTo = txtSendTo.Text;
  99. po.SendToAddress = txtSendToAddress.Text;
  100. if (chkKapalCepat.Checked) po.Transportation += "[Kapal Cepat]";
  101. if (chkKapalLambat.Checked) po.Transportation += "[Kapal Lambat]";
  102. if (chkTrucking.Checked) po.Transportation += "[Trucking]";
  103. if (chkLainLain.Checked) po.Transportation += "[Lain-Lain]";
  104. po.Subtotal = txtTotalNilaiBarang.EditValue.ToDecimal();
  105. po.BeratDimensi = txtTotalBeratDimensi.EditValue.ToDecimal();
  106. po.UnitPrice = txtUnitPrice.EditValue.ToDecimal();
  107. po.TotalBiayaExpedisi = txtTotalBiayaExpedisi.EditValue.ToDecimal();
  108. po.PPNPercent = txtTaxPercent.EditValue.ToDecimal();
  109. po.PPNAmount = txtTax.EditValue.ToDecimal();
  110. po.AsuransiPercent = txtAsuransiPercent.EditValue.ToDecimal();
  111. po.AsuransiAmount = txtAsuransi.EditValue.ToDecimal();
  112. po.BiayaPalletized = txtBiayaPalletized.EditValue.ToDecimal();
  113. po.BiayaHandlingIn = txtBiayaHandlingIn.EditValue.ToDecimal();
  114. po.TotalBiayaExpedisi = txtTotalBiayaExpedisi.EditValue.ToDecimal();
  115. po.Total = txtTotal.EditValue.ToDecimal();
  116. db.ExecuteCommand("DELETE FROM dbo.DetailPOtoSupplierExpedisi WHERE idPOtoSupplierExpedisi = " + _id);
  117. foreach (DetailPOtoSupplierExpedisi item in detailPOtoSupplierExpedisiBindingSource)
  118. {
  119. DetailPOtoSupplierExpedisi detail = new DetailPOtoSupplierExpedisi();
  120. detail.NamaBarang = item.NamaBarang;
  121. detail.NilaiBarang = item.NilaiBarang;
  122. detail.BeratDimensi = item.BeratDimensi;
  123. po.DetailPOtoSupplierExpedisis.Add(detail);
  124. }
  125. db.SubmitChanges();
  126. XtraMessageBox.Show("Data saved successfully.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  127. Close();
  128. }
  129. catch (Exception ex)
  130. {
  131. XtraMessageBox.Show("Gagal.\n" + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
  132. }
  133. Cursor.Current = Cursors.Default;
  134. }
  135. private void btnCancel_Click(object sender, EventArgs e)
  136. {
  137. DialogResult = XtraMessageBox.Show("Are you sure want to cancel this transaction?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  138. if (DialogResult == DialogResult.Yes)
  139. {
  140. Close();
  141. }
  142. }
  143. private void CalculateTotal(object sender, EventArgs e)
  144. {
  145. try
  146. {
  147. //txtTotalBiayaExpedisi.EditValue = txtTotalBeratDimensi.EditValue.ToDecimal() * txtUnitPrice.EditValue.ToDecimal();
  148. txtTotal.EditValue = txtTotalBiayaExpedisi.EditValue.ToDecimal() + txtTax.EditValue.ToDecimal() + txtAsuransi.EditValue.ToDecimal() + txtBiayaPalletized.EditValue.ToDecimal() + txtBiayaHandlingIn.EditValue.ToDecimal();
  149. }
  150. catch { }
  151. }
  152. private void txtTaxPercent_EditValueChanged(object sender, EventArgs e)
  153. {
  154. txtTax.EditValue = txtTotalBiayaExpedisi.EditValue.ToDecimal() * txtTaxPercent.EditValue.ToDecimal() / 100;
  155. }
  156. private void txtAsuransiPercent_EditValueChanged(object sender, EventArgs e)
  157. {
  158. txtAsuransi.EditValue = txtTotalBiayaExpedisi.EditValue.ToDecimal() * txtAsuransiPercent.EditValue.ToDecimal() / 100;
  159. }
  160. private void gridView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
  161. {
  162. try
  163. {
  164. var details = detailPOtoSupplierExpedisiBindingSource.Cast<DetailPOtoSupplierExpedisi>();
  165. txtTotalNilaiBarang.EditValue = details.Sum(x => x.NilaiBarang);
  166. txtTotalBeratDimensi.EditValue = details.Sum(x => x.BeratDimensi);
  167. }
  168. catch { }
  169. }
  170. private void cmbTo_SelectedIndexChanged(object sender, EventArgs e)
  171. {
  172. try
  173. {
  174. Cursor.Current = Cursors.WaitCursor;
  175. if (db.Suppliers.Any(x => x.Name == cmbTo.Text && x.Active == true))
  176. {
  177. var supplier = db.Suppliers.First(x => x.Name == cmbTo.Text && x.Active == true);
  178. txtAddress.Text = supplier.Address;
  179. txtPIC.Text = supplier.Person;
  180. txtPhone.Text = supplier.Phone;
  181. }
  182. }
  183. catch { }
  184. Cursor.Current = Cursors.Default;
  185. }
  186. }
  187. }