public bool Update(CT_PHIEUTHANHLY ctptl) { int result = 0; try { SqlConnection con = new SqlConnection(db.connectionStr); SqlCommand cmd = new SqlCommand("update_CTPTLY", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ptl_id", SqlDbType.NVarChar, 50); cmd.Parameters.Add("@vt_id", SqlDbType.NVarChar, 20); cmd.Parameters.Add("@id_nhapkhoct", SqlDbType.VarChar, 30); cmd.Parameters.Add("@cttl_thuhoi", SqlDbType.Float); cmd.Parameters.Add("@cttl_thanhly", SqlDbType.Float); cmd.Parameters.Add("@solg", SqlDbType.Float); cmd.Parameters.Add("@dongia", SqlDbType.Float); cmd.Parameters["@ptl_id"].Value = ctptl.Ptl_id; cmd.Parameters["@vt_id"].Value = ctptl.Vt_id; cmd.Parameters["@id_nhapkhoct"].Value = ctptl.Id_ctnk; cmd.Parameters["@cttl_thuhoi"].Value = ctptl.Cp_thuhoi; cmd.Parameters["@cttl_thanhly"].Value = ctptl.Cp_thanhly; cmd.Parameters["@solg"].Value = ctptl.Solg; cmd.Parameters["@dongia"].Value = ctptl.Gia; con.Open(); result = cmd.ExecuteNonQuery(); con.Close(); } catch { } return(result > 0); }
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; } }