/// <summary> /// Function to insert values to Privilege Table /// </summary> /// <param name="privilegeinfo"></param> public void PrivilegeAdd(PrivilegeInfo privilegeinfo) { try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("PrivilegeAdd", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@formName", SqlDbType.VarChar); sprmparam.Value = privilegeinfo.FormName; sprmparam = sccmd.Parameters.Add("@action", SqlDbType.VarChar); sprmparam.Value = privilegeinfo.Action; sprmparam = sccmd.Parameters.Add("@roleId", SqlDbType.Decimal); sprmparam.Value = privilegeinfo.RoleId; sprmparam = sccmd.Parameters.Add("@exatra1", SqlDbType.VarChar); sprmparam.Value = privilegeinfo.Extra1; sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar); sprmparam.Value = privilegeinfo.Extra2; sccmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sqlcon.Close(); } }
/// <summary> /// Function to get particular values from Privilege Table based on the parameter /// </summary> /// <param name="decRoleId"></param> /// <returns></returns> public PrivilegeInfo PrivilegeView(decimal decRoleId) { PrivilegeInfo privilegeinfo = new PrivilegeInfo(); SqlDataReader sdrreader = null; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("PrivilegeView", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@roleId", SqlDbType.Decimal); sprmparam.Value = decRoleId; sdrreader = sccmd.ExecuteReader(); while (sdrreader.Read()) { privilegeinfo.PrivilegeId = decimal.Parse(sdrreader[0].ToString()); privilegeinfo.FormName = sdrreader[1].ToString(); privilegeinfo.Action = sdrreader[2].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sdrreader.Close(); sqlcon.Close(); } return(privilegeinfo); }
/// <summary> /// Save Function /// </summary> public void SaveFunction() { try { PrivilegeInfo infoPrivilege = new PrivilegeInfo(); PrivilegeSP spPrivilege = new PrivilegeSP(); infoPrivilege.RoleId = Convert.ToDecimal(cmbRole.SelectedValue); infoPrivilege.Extra1 = string.Empty; infoPrivilege.Extra2 = string.Empty; foreach (Control tabPage in tcPrivillage.Controls) { string strTabPage = tabPage.Text; if (strTabPage == "Company") { infoPrivilege.FormName = "frm" + strTabPage +"Creation"; foreach (Control cbxCompany in tabPage.Controls) { if (cbxCompany is CheckBox) { CheckBox cbx = (CheckBox)cbxCompany; if (cbx.Checked == true) { string strCbx = cbx.Text.Replace(" ",string.Empty); if (strCbx == "Edit") { infoPrivilege.Action = "Update"; } else { infoPrivilege.Action = strCbx; } spPrivilege.PrivilegeAdd(infoPrivilege); } } } } else { foreach (Control gbxControl in tabPage.Controls) { if (gbxControl is GroupBox) { string strFormName = gbxControl.Text.Replace(" ", string.Empty); foreach (Control cbxControl in gbxControl.Controls) { CheckBox cbx = (CheckBox)cbxControl; if (cbx.Checked == true) { string strCbx = cbx.Text.Replace(" ", string.Empty); if (gbxControl.Text == "Transactions" || gbxControl.Text == "Payroll") { infoPrivilege.FormName = "frm" + strCbx; infoPrivilege.Action = "View"; spPrivilege.PrivilegeAdd(infoPrivilege); } /*------------------------------------*/ else { if (strCbx != "All" && strCbx != "Register") { if (gbxControl.Text == "Price List" || gbxControl.Text == "Standerd Rate") { infoPrivilege.FormName = "frm" + strFormName + "Popup"; if (strCbx == "Add") { infoPrivilege.Action = "Save"; } else if (strCbx == "Edit") { infoPrivilege.Action = "Update"; } else if (strCbx == "Delete") { infoPrivilege.Action = "Delete"; } spPrivilege.PrivilegeAdd(infoPrivilege); } else { infoPrivilege.FormName = "frm" + strFormName; if (strCbx == "Add") { infoPrivilege.Action = "Save"; } else if (strCbx == "Edit") { infoPrivilege.Action = "Update"; } else if (strCbx == "Delete") { infoPrivilege.Action = "Delete"; } else if (strCbx == "View") { infoPrivilege.Action = "View"; } spPrivilege.PrivilegeAdd(infoPrivilege); } } else if (strCbx == "Register") { string strFormNameCreationRemove = "frm" + strFormName.Replace("Creation", string.Empty) + "Register"; string strFormNameVoucherRemove = "frm" + strFormName.Replace("Voucher", string.Empty) + "Register"; infoPrivilege.FormName = strFormNameCreationRemove; infoPrivilege.Action = "View"; spPrivilege.PrivilegeAdd(infoPrivilege); } } } } } else { if (gbxControl is CheckBox) { CheckBox cbx = (CheckBox)gbxControl; if (cbx.Checked == true) { string strFormName = "frm" + gbxControl.Text.Replace(" ", string.Empty); infoPrivilege.FormName = strFormName; infoPrivilege.Action = "View"; spPrivilege.PrivilegeAdd(infoPrivilege); } } } } } } AllTabpageClear(); } catch (Exception ex) { MessageBox.Show("RLPRST:9" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to Delete an items /// </summary> public void DeleteFunction() { try { PrivilegeInfo infoPrivilege = new PrivilegeInfo(); PrivilegeSP spPrivilege = new PrivilegeSP(); decimal decRoleId = Convert.ToDecimal(cmbRole.SelectedValue); spPrivilege.PrivilegeDeleteTabel(decRoleId); } catch (Exception ex) { MessageBox.Show("RLPRST:8" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to get particular values from Privilege Table based on the parameter /// </summary> /// <param name="decRoleId"></param> /// <returns></returns> public PrivilegeInfo PrivilegeView(decimal decRoleId) { PrivilegeInfo privilegeinfo = new PrivilegeInfo(); SqlDataReader sdrreader = null; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("PrivilegeView", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@roleId", SqlDbType.Decimal); sprmparam.Value = decRoleId; sdrreader = sccmd.ExecuteReader(); while (sdrreader.Read()) { privilegeinfo.PrivilegeId = decimal.Parse(sdrreader[0].ToString()); privilegeinfo.FormName = sdrreader[1].ToString(); privilegeinfo.Action = sdrreader[2].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sdrreader.Close(); sqlcon.Close(); } return privilegeinfo; }