private void btnDEL_Click(object sender, EventArgs e) { try { string sFromWorkCenter = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridColFromWorkCenter).ToString().Trim(); if (sFromWorkCenter == "") { throw new Exception("Please Choose data"); } DialogResult d = MessageBox.Show("Delete " + sFromWorkCenter + "?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (d != DialogResult.Yes) { return; } //判断是否使用 DAL._InvProcessPrice dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._InvProcessPrice(); string sSQL = dal.Delete(sFromWorkCenter); int iCou = DbHelperSQL.ExecuteSql(sSQL); if (iCou > 0) { MessageBox.Show("OK"); GetGrid(); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnSave_Click(object sender, EventArgs e) { string sErr = ""; int iCount = 0; try { gridView1.PostEditor(); SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); for (int i = 0; i < gridView1.RowCount; i++) { int iID = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColiID)); string iState = gridView1.GetRowCellValue(i, gridColiState).ToString().Trim(); if (iState == "") { continue; } if (gridView1.GetRowCellValue(i, gridColFromWorkCenter).ToString().Trim() == "") { continue; } Model._InvProcessPrice model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._InvProcessPrice(); decimal dPrice = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPrice)); if (dPrice <= 0) { sErr = sErr + "Row " + (i + 1).ToString() + " Please set price\n"; continue; } model.Price = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPrice)); model.FromWorkCenter = gridView1.GetRowCellValue(i, gridColFromWorkCenter).ToString().Trim(); model.CaseType = gridView1.GetRowCellValue(i, gridColCaseType).ToString().Trim(); model.Remark = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim(); if (iID == 0) { model.CreateUid = sUserID; model.CreateDate = dNowDate; DAL._InvProcessPrice dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._InvProcessPrice(); sSQL = dal.Add(model); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { model.CreateUid = gridView1.GetRowCellValue(i, gridColCreateUid).ToString().Trim(); model.CreateDate = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColCreateDate)); DAL._InvProcessPrice dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._InvProcessPrice(); sSQL = dal.Update(model); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } if (sErr != "") { throw new Exception(sErr); } if (iCount > 0) { tran.Commit(); MessageBox.Show("OK"); GetGrid(); } else { throw new Exception("no data"); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }