private void btnSave_Click(object sender, EventArgs e) { lbAlertMessage.Text = ""; if (GridUsertype.CurrentRow != null) { string UserID = Convert1.ToString(GridUsertype.CurrentRow.Cells[1].Value); string UserName = GridUsertype.CurrentRow.Cells[2].Value.ToString(); var listUserroom = (from t1 in dbc.mst_user_rooms where t1.mut_username == UserName select t1); dbc.mst_user_rooms.DeleteAllOnSubmit(listUserroom); for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++) { if (Convert1.ToBoolean(dataGridView1[0, i].Value) == true) { int mrmid = Utility.GetInteger(dataGridView1[1, i].Value); mst_user_type usermut = (from t1 in dbc.mst_user_types where t1.mut_username == UserName select t1).FirstOrDefault(); mst_user_room newitem = new mst_user_room(); newitem.mst_user_type = usermut; newitem.mut_id = usermut.mut_id; newitem.mut_username = UserName; newitem.mrm_id = mrmid; dbc.mst_user_rooms.InsertOnSubmit(newitem); } } dbc.SubmitChanges(); lbAlertMessage.Text = "Save data completed."; } else { lbAlertMessage.Text = "Please select user for edit."; } }
private void SaveData() { try { mst_user_type currentmut = (mst_user_type)mstUserTypebindingSource1.Current; if (currentmut != null) { //start date currentmut.mut_effective_date = txtEffectDate.Value; //end date if (rdoExpireDt.Checked) { currentmut.mut_expire_date = txtExpireDate.Value; } //status if (ChStatus.Checked == true) { currentmut.mut_status = 'A'; } else { currentmut.mut_status = 'I'; } //Gender currentmut.mut_gender = Program.GetValueRadioTochar(pnlGender); //mutType currentmut.mut_type = Program.GetValueRadioTochar(pnlmut_type); //Admin Type if (currentmut.mut_admin == true) { currentmut.mut_admin_type = Program.GetValueRadioTochar(pnlAdminType); } else { currentmut.mut_admin_type = null; } } mstUserTypebindingSource1.EndEdit(); dbc.SubmitChanges(); currentmut = (mst_user_type)mstUserTypebindingSource1.Current; for (int i = 0; i < gvUserRoom.Rows.Count; i++) { if (gvUserRoom["userRoomID", i].Value == null) { mst_user_room newRoom = new mst_user_room(); newRoom.mut_id = currentmut.mut_id; newRoom.mrm_id = (int)gvUserRoom["userMrmID", i].Value; newRoom.mut_username = currentmut.mut_username; dbc.mst_user_rooms.InsertOnSubmit(newRoom); } else if (!gvUserRoom.Rows[i].Visible) { int removeRowID = (int)gvUserRoom["userRoomID", i].Value; var objUserRoom = (from row in dbc.mst_user_rooms where row.row_id == removeRowID select row).FirstOrDefault(); dbc.mst_user_rooms.DeleteOnSubmit(objUserRoom); } } dbc.SubmitChanges(); lbmsgalert.Text = "Save data completed."; } catch (Exception ex) { //Program.MessageError(ex.Message); lbmsgalert.Text = "Error:" + ex.Message; } }