コード例 #1
0
        private void UpdateData()
        {
            string   sql;
            DataView dvMain = tbMain.DefaultView;

            try
            {
                _db.BeginMultiTrans();
                dvMain.RowStateFilter = DataViewRowState.ModifiedOriginal;
                foreach (DataRowView dr in dvMain)
                {
                    //Trường hợp thêm mới mà chưa thêm ngày
                    if (dr.Row["ngaygd"] == DBNull.Value && dr["ngaygd"] == DBNull.Value)
                    {
                        dr.Row.SetColumnError(dr.Row.Table.Columns["ngaygd"], "dữ liệu chưa hợp lệ");
                        continue;
                    }//trường hợp thêm mới
                    else if (dr.Row["ngaygd"] != DBNull.Value && dr["ngaygd"] == DBNull.Value)
                    {
                        sql = genInsertString(dr.Row);
                        _db.UpdateByNonQuery(sql);
                    }
                    else if (dr.Row["ngaygd"] != DBNull.Value && dr["ngaygd"] != DBNull.Value)
                    {
                        sql = genUpdateString(dr.Row);
                        _db.UpdateByNonQuery(sql);
                    }
                    if (_db.HasErrors)
                    {
                        break;
                    }
                    else
                    {
                        dr.Row.AcceptChanges();
                    }
                }
                if (_db.HasErrors)
                {
                    _db.RollbackMultiTrans();
                }
                else
                {
                    _db.EndMultiTrans();
                }
            }
            catch (Exception ex)
            {
                _db.RollbackMultiTrans();
            }
            dvMain.RowStateFilter = DataViewRowState.CurrentRows;
        }
コード例 #2
0
ファイル: Imation.cs プロジェクト: trancongvy/CBADev17
        private bool SaveImation()
        {
            string sql = "delete plImation where sohieu='" + Sohieu.ToString() + "'";

            db.UpdateByNonQuery(sql);
            foreach (DataRow dr in MasterTb.Rows)
            {
                sql = "Insert into plImation ([MaCongdoan], [MaCongdoanMe], [MaSP], [MaWC], [Thutu], [Soluong], [SLThaotac], [LenOfRouting], [ToTalTime], [Stime], [Etime], [Sohieu]) values ('" +
                      dr["MaCongdoan"].ToString() + "','" + dr["MaCongdoanMe"].ToString() + "','" + dr["MaSP"].ToString() + "','" + dr["MaWC"].ToString() + "'," +
                      dr["Thutu"].ToString() + "," + dr["Soluong"].ToString() + "," + dr["SlThaotac"].ToString() + "," + dr["LenOfRouting"].ToString() + "," +
                      dr["ToTaltime"].ToString() + "," + dr["Stime"].ToString() + "," + dr["Etime"].ToString() + ",'" + Sohieu + "')";
                db.UpdateByNonQuery(sql);
                if (db.HasErrors)
                {
                    return(false);
                }
            }
            return(true);
        }