private KHO_CHI_TIET layTTKHOCT(string id_ctpn) { string vt_id = daoThuoc.getIDTHUOCbyTEN(txtTenVT.Text); string kho = cbbKho.SelectedValue.ToString(); DateTime thoidiem = DateTime.Parse(dtpNgayNhap.Text); int solg = int.Parse(txtSoLG.Text); float dongia = float.Parse(txtGiaNhap.Text); string tt = ""; string ctpn = id_ctpn; int ngvu = 1; KHO_CHI_TIET kct = new KHO_CHI_TIET(kho, ngvu, vt_id, thoidiem, ctpn, solg, dongia, tt, ""); return(kct); }
public bool Insert_KCT(KHO_CHI_TIET kct) { try { SqlConnection conn = new SqlConnection(db.connectionStr); SqlCommand cmd = new SqlCommand("insert_CTKho", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@kho_id", SqlDbType.NVarChar, 20); cmd.Parameters.Add("@ngvu_id", SqlDbType.NVarChar, 50); cmd.Parameters.Add("@vattu_id", SqlDbType.NVarChar, 20); cmd.Parameters.Add("@thoidiem", SqlDbType.DateTime); cmd.Parameters.Add("@id_nhapkhoct", SqlDbType.VarChar, 30); cmd.Parameters.Add("@solg", SqlDbType.Int); cmd.Parameters.Add("@gia", SqlDbType.Float); cmd.Parameters.Add("@tt_id", SqlDbType.NVarChar, 20); cmd.Parameters.Add("@id_ptl", SqlDbType.VarChar, 50); cmd.Parameters["@kho_id"].Value = kct.Kho_id; cmd.Parameters["@ngvu_id"].Value = kct.Ngvu; cmd.Parameters["@vattu_id"].Value = kct.Vattu; cmd.Parameters["@thoidiem"].Value = kct.Thoidiem; cmd.Parameters["@id_nhapkhoct"].Value = kct.Id_nhapkho; cmd.Parameters["@solg"].Value = kct.Solg; cmd.Parameters["@gia"].Value = kct.Dongia; cmd.Parameters["@tt_id"].Value = kct.Toathuoc; cmd.Parameters["@id_ptl"].Value = kct.Id_ptl; conn.Open(); int result = cmd.ExecuteNonQuery(); conn.Close(); return(result > 0); } catch (SqlException ex) { MessageBox.Show(ex.Message); return(false); } }
private void btnThemThuoc_Click(object sender, EventArgs e) { if (KiemTraLoi() == "") { string ctpn_id = daoCTPN.Get_ID_Auto(); string pn_id = txtMaPN.Text; string vt_id = daoThuoc.getIDTHUOCbyTEN(txtTenVT.Text); string ten = txtTenVT.Text; string dvt = txtDVT.Text; string hoatchat = txtHoatChat.Text; int solg = int.Parse(txtSoLG.Text); float gianhap = float.Parse(txtGiaNhap.Text); string solo = txtSoLo.Text; DateTime ngaysx = Convert.ToDateTime(DateTime.Parse(dtpNgaySX.Text).ToShortDateString()); DateTime hansd = Convert.ToDateTime(DateTime.Parse(dtpHanSuDung.Text).ToShortDateString()); float vat = 0; if (txtVAT.TextLength != 0) { vat = float.Parse(txtVAT.Text); } float truocthue = solg * gianhap; float sauthue = truocthue + ((truocthue * vat) / 100); string hamlg = txtHamLuong.Text; string quycach = txtQuyCach.Text; float giaban = float.Parse(txtGiaBan.Text); CHITIET_PHIEUNHAP ctpn = new CHITIET_PHIEUNHAP(ctpn_id, hoatchat, dvt, solg, gianhap, solo, ngaysx, hansd, truocthue, sauthue, hamlg, quycach, giaban, vt_id, pn_id); if (pn_id != "") { if (daoPNK.KiemTraTrung(pn_id) == 0) { lbLoi2.Text = "Chưa có phiếu nhập " + txtMaPN.Text; } else { if (daoCTPN.KiemTraVT(pn_id, vt_id) == 0) { if (daoCTPN.Insert(ctpn)) { KHO_CHI_TIET kct = layTTKHOCT(ctpn_id); daoKCT.Insert_KCT(kct); } resetThuoc(); } else { if (daoCTPN.Update(ctpn)) { KHO_CHI_TIET kct = layTTKHOCT(lbID_CTPN.Text); daoKCT.Update_KCT(kct); } } } } else { lbLoi2.Text = "Chưa có phiếu nhập"; } grcListVT.DataSource = daoCTPN.Get_CTPN_TheoID(pn_id); } }
private void btnVT_TL_Click(object sender, EventArgs e) { if (KiemTraLoi() == "") { string ptl_id = txtMaPTL.Text; string vt_id = lbID_VT.Text; string id_nhapkho = lbIDNK.Text; float cpthanhly = 0; if (txtCPTL.TextLength != 0) { cpthanhly = float.Parse(txtCPTL.Text); } else { cpthanhly = 0; } float solg = 0; if (txtSoLG.TextLength == 0) { solg = 0; } else { solg = float.Parse(txtSoLG.Text); } float gia = 0; if (txtGia.TextLength == 0) { gia = 0; } else { gia = float.Parse(txtGia.Text); } float cpthuhoi = solg * gia; CT_PHIEUTHANHLY ctptl = new CT_PHIEUTHANHLY(ptl_id, vt_id, id_nhapkho, cpthuhoi, cpthanhly, solg, gia); KHO_CHI_TIET kct = new KHO_CHI_TIET(cbbKho.SelectedValue.ToString(), 3, vt_id, DateTime.Now, id_nhapkho, solg, gia, "", ptl_id); float solgton = float.Parse(lbSoLgTon.Text); if (ptl_id != "") { if (daoPTL.KiemTraTrung(ptl_id) == 0) { lbLoi2.Text = "Chưa có phiếu thanh lý " + txtMaPTL.Text; } else { if (daoCTPTL.KiemTraVT(ptl_id, vt_id) == 0) { if (daoCTPTL.Insert(ctptl)) { float slgconlai = solgton - solg; daoKCT.Insert_KCT(kct); daoCTPN.Update_CTPN_SOLG(id_nhapkho, int.Parse(slgconlai.ToString())); lbSoLgTon.Text = slgconlai.ToString(); } } else { if (daoCTPTL.Update(ctptl)) { float solgcu = float.Parse(lbSolgCu.Text); float solgconlai = 0; float solgmoi = 0; if (solg > solgcu) { solgmoi = solg - solgcu; solgconlai = solgton - solgmoi; } else if (solgcu > solg) { solgmoi = solgcu - solg; solgconlai = solgton + solgmoi; } daoKCT.Update_KCT(kct); daoCTPN.Update_CTPN_SOLG(id_nhapkho, int.Parse(solgconlai.ToString())); lbSoLgTon.Text = solgconlai.ToString(); } } } } else { lbLoi2.Text = "Chưa có phiếu thanh lý"; } grcListVT.DataSource = daoCTPTL.Get_CTPTL_TheoID(ptl_id); gcVT.DataSource = daoPTL.get_VatTuTon(txtTenVT.Text); lbSolgCu.Text = txtSoLG.Text; } }