/// <summary> /// This method is used to delete the particular record from user master table. /// </summary> protected void btnDelete_Click(object sender, System.EventArgs e) { if (dropUserID.SelectedIndex == 0) { RMG.MessageBox.Show("Please select the User ID"); return; } int output = 0; try { DBOperations.DBUtil obj = new DBOperations.DBUtil(); obj.Insert_or_Update("delete from User_Master where UserID='" + dropUserID.SelectedItem.Value + "'", ref output); obj.Insert_or_Update("delete from privileges where User_ID='" + dropUserID.SelectedItem.Value + "'", ref output); dropUserID.Items.Remove(dropUserID.SelectedItem.Value); MessageBox.Show("User Deleted"); Clear(); GetNextUserID(); lblUserID.Visible = true; btnEdit.Visible = true; dropUserID.Visible = false; } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:User_Profile.aspx,Method:btnDelete_Click EXCEPTION: " + ex.Message + " " + uid); } }
// private byte[] Encrypt(string pswd) // { // RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider(); // byte[]key=System.Text.ASCIIEncoding.ASCII.GetBytes("shashank"); // byte[]IV=System.Text.ASCIIEncoding.ASCII.GetBytes("shashank"); // byte[]data=System.Text.ASCIIEncoding.ASCII.GetBytes(pswd); // MemoryStream msEncrypt = new MemoryStream(); // //CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write); // CryptoStream csEncrypt = new CryptoStream(msEncrypt, rc2CSP.CreateEncryptor(key,IV), CryptoStreamMode.Write); // csEncrypt.Write(data,0,data.Length); // csEncrypt.FlushFinalBlock(); // return msEncrypt.ToArray(); // //txtres.Text=System.Text.ASCIIEncoding.ASCII.GetString(msEncrypt.ToArray()); // } /// <summary> /// This method is used to fatch the all user ID from user master table and fill the dropdownlist on edit time. /// </summary> protected void btnEdit_Click(object sender, System.EventArgs e) { lblUserID.Visible = false; btnEdit.Visible = false; dropUserID.Visible = true; #region Fetch All User ID try { dropUserID.Items.Clear(); dropUserID.Items.Add("Select"); DBOperations.DBUtil obj = new DBOperations.DBUtil(); SqlDataReader SqlDtr = null; obj.SelectQuery("select UserID from User_Master", ref SqlDtr); while (SqlDtr.Read()) { dropUserID.Items.Add(SqlDtr.GetValue(0).ToString()); } SqlDtr.Close(); } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:User_Profile.aspx,Method:btnEdit_Click EXCEPTION: " + ex.Message + " " + uid); } #endregion }
/// <summary> /// This method is used to fatch the all role ID from roles table and fill the dropdownlist on edit time. /// </summary> protected void btnEdit_Click(object sender, System.EventArgs e) { dropRoleID.SelectedIndex = 0; lblRoleID.Visible = false; btnEdit.Visible = false; dropRoleID.Visible = true; btnUpdate.Text = "Update"; try { #region Fetch All Role ID dropRoleID.Items.Clear(); dropRoleID.Items.Add("Select"); DBOperations.DBUtil obj = new DBOperations.DBUtil(); SqlDataReader SqlDtr = null; obj.SelectQuery("select Role_ID from Roles", ref SqlDtr); while (SqlDtr.Read()) { dropRoleID.Items.Add(SqlDtr.GetValue(0).ToString()); } SqlDtr.Close(); #endregion } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:btnEdit_Click EXCEPTION: " + ex.Message + " userid " + uid); } }
/// <summary> /// This method is used to update the Role with the help of ProRolesUpdate procedure. /// </summary> protected void btnUpdate_Click(object sender, System.EventArgs e) { EmployeeClass obj = new EmployeeClass(); obj.Role_Name = txtRoleName.Text.ToString(); obj.Description = txtDesc.Text.ToString(); try { if (dropRoleID.Visible) { obj.Role_ID = dropRoleID.SelectedItem.Value; obj.UpdateRoles(); CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:btnUpdateClick Role name " + obj.Role_Name + " Updated " + uid); MessageBox.Show("Role Updated"); } else { #region Check Role Already Created or Not int count = 0; DBOperations.DBUtil dbobj = new DBOperations.DBUtil(); dbobj.ExecuteScalar("select count(*) from Roles where Role_Name='" + txtRoleName.Text.Trim() + "'", ref count); if (count > 0) { MessageBox.Show("Role already Exists"); return; } #endregion obj.Role_ID = lblRoleID.Text.ToString(); obj.InsertRoles(); CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:btnUpdate_Click Role Name " + obj.Role_Name + " Created " + uid); MessageBox.Show("Role Created"); } Clear(); GetNextRoleID(); lblRoleID.Visible = true; dropRoleID.Visible = false; btnEdit.Visible = true; btnUpdate.Text = "Save"; dropRoleID.SelectedIndex = 0; } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:btnUpdate_Click EXCEPTION: " + ex.Message + " userid " + uid); } }
/// <summary> /// This method is used to fatch the record according to select user from dropdownlist on edit time. /// </summary> protected void dropUserID_SelectedIndexChanged(object sender, System.EventArgs e) { try { Clear(); DBOperations.DBUtil obj = new DBOperations.DBUtil(); SqlDataReader SqlDtr = null; string Name = ""; obj.SelectQuery("select loginname, password, username,role_name from user_master um, roles r where um.role_id=r.role_id and UserId='" + dropUserID.SelectedItem.Value + "'", ref SqlDtr); while (SqlDtr.Read()) { txtLoginName.Text = SqlDtr.GetValue(0).ToString(); txtPassword.Text = SqlDtr.GetValue(1).ToString(); //txtFName.Text=SqlDtr.GetValue(2).ToString(); Name = SqlDtr.GetValue(2).ToString(); DropRole.SelectedIndex = DropRole.Items.IndexOf(DropRole.Items.FindByValue(SqlDtr.GetValue(3).ToString())); } SqlDtr.Close(); string[] UName = null; if (Name.IndexOf(" ") > 0) { UName = Name.Split(new char[] { ' ' }, Name.Length); if (UName.Length > 2) { txtFName.Text = UName[0].ToString(); txtMName.Text = UName[1].ToString(); txtLName.Text = UName[2].ToString(); } else { txtFName.Text = UName[0].ToString(); txtLName.Text = UName[1].ToString(); } } else { txtFName.Text = Name.Trim(); } } catch (Exception ex) { MessageBox.Show("Please Select User ID"); CreateLogFiles.ErrorLog("Form:User_Profile.aspx,Method:dropUserID_SelectedIndexChanged EXCEPTION: " + ex.Message + " " + uid); } }
/// <summary> /// This method is used to fatch the role infomatoin when u select the role ID from dropdownlist. /// </summary> protected void dropRoleID_SelectedIndexChanged(object sender, System.EventArgs e) { try { Clear(); RolesModel role = new RolesModel(); DBOperations.DBUtil obj = new DBOperations.DBUtil(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUri); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var Res = client.GetAsync("api/Roles/GetSelectedRoleIDData?RoleID=" + dropRoleID.SelectedItem.Value).Result; if (Res.IsSuccessStatusCode) { var id = Res.Content.ReadAsStringAsync().Result; role = JsonConvert.DeserializeObject <RolesModel>(id); } else { Res.EnsureSuccessStatusCode(); } } if (role != null) { txtRoleName.Text = role.Role_Name.ToString(); txtDesc.Text = role.Description.ToString(); } CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:dropRoleID_SelectedIndexChanged " + " userid " + uid); } catch (Exception ex) { MessageBox.Show("Please select Role ID"); CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:dropRoleID_SelectedIndexChanged" + ex.Message + " EXCEPTION " + uid); } }
/// <summary> /// This method is used to delete the particular Role ID from roles table which role id select from /// dropdownlist on edit time. /// </summary> protected void btnDelete_Click(object sender, System.EventArgs e) { try { if (dropRoleID.SelectedIndex == 0) { RMG.MessageBox.Show("Please select the Role ID"); return; } int output = 0; DBOperations.DBUtil obj = new DBOperations.DBUtil(); obj.ExecuteScalar("select count(*) from User_master where Role_ID='" + dropRoleID.SelectedItem.Value + "'", ref output); if (output > 0) { MessageBox.Show("Selected Role cannot be Deleted"); return; } else { obj.Insert_or_Update("delete from roles where Role_Id='" + dropRoleID.SelectedItem.Value + "'", ref output); dropRoleID.Items.Remove(dropRoleID.SelectedItem.Value); MessageBox.Show("Role Deleted"); CreateLogFiles.ErrorLog("Form:Roles.aspx,Method: btnDelete_Click" + uid); Clear(); lblRoleID.Visible = true; dropRoleID.Visible = false; btnEdit.Visible = true; btnUpdate.Text = "Save"; GetNextRoleID(); dropRoleID.SelectedIndex = 0; } } catch (Exception ex) { MessageBox.Show("Please select Role ID"); CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:btnDelete_Click" + ex.Message + " EXCEPTION " + uid); } }
/// <summary> /// This method is used to fatch the role infomatoin when u select the role ID from dropdownlist. /// </summary> protected void dropRoleID_SelectedIndexChanged(object sender, System.EventArgs e) { try { Clear(); DBOperations.DBUtil obj = new DBOperations.DBUtil(); SqlDataReader SqlDtr = null; obj.SelectQuery("select * from roles where Role_Id='" + dropRoleID.SelectedItem.Value + "'", ref SqlDtr); while (SqlDtr.Read()) { txtRoleName.Text = SqlDtr.GetValue(1).ToString(); txtDesc.Text = SqlDtr.GetValue(2).ToString(); } SqlDtr.Close(); CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:dropRoleID_SelectedIndexChanged " + " userid " + uid); } catch (Exception ex) { MessageBox.Show("Please select Role ID"); CreateLogFiles.ErrorLog("Form:Roles.aspx,Method:dropRoleID_SelectedIndexChanged" + ex.Message + " EXCEPTION " + uid); } }
/// <summary> /// This method is used to update the customer balance after update the customer record. /// </summary> public void CustomerBalanceUpdation() { InventoryClass obj = new InventoryClass(); InventoryClass obj1 = new InventoryClass(); SqlCommand cmd; DBOperations.DBUtil dbobj = new DBOperations.DBUtil(System.Configuration.ConfigurationSettings.AppSettings["Servosms"], true); SqlConnection Con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["Servosms"]); SqlDataReader rdr1 = null, rdr = null; dbobj.SelectQuery("select Ledger_ID from Ledger_Master l,customer c where cust_name=ledger_name", ref rdr1); while (rdr1.Read()) { dbobj.SelectQuery("select * from AccountsLedgerTable where Ledger_ID='" + rdr1["Ledger_ID"].ToString() + "' order by entry_date", ref rdr); double Bal = 0; string BalType = ""; int i = 0; while (rdr.Read()) { if (i == 0) { BalType = rdr["Bal_Type"].ToString(); i++; } if (double.Parse(rdr["Credit_Amount"].ToString()) != 0) { if (BalType == "Cr") { Bal += double.Parse(rdr["Credit_Amount"].ToString()); BalType = "Cr"; } else { Bal -= double.Parse(rdr["Credit_Amount"].ToString()); if (Bal < 0) { Bal = double.Parse(Bal.ToString().Substring(1)); BalType = "Cr"; } else { BalType = "Dr"; } } } else if (double.Parse(rdr["Debit_Amount"].ToString()) != 0) { if (BalType == "Dr") { Bal += double.Parse(rdr["Debit_Amount"].ToString()); } else { Bal -= double.Parse(rdr["Debit_Amount"].ToString()); if (Bal < 0) { Bal = double.Parse(Bal.ToString().Substring(1)); BalType = "Dr"; } else { BalType = "Cr"; } } } Con.Open(); cmd = new SqlCommand("update AccountsLedgerTable set Balance='" + Bal.ToString() + "',Bal_Type='" + BalType + "' where Ledger_ID='" + rdr["Ledger_ID"].ToString() + "' and Particulars='" + rdr["Particulars"].ToString() + "' ", Con); cmd.ExecuteNonQuery(); cmd.Dispose(); Con.Close(); } rdr.Close(); } rdr1.Close(); //**************** dbobj.SelectQuery("select Cust_ID from Customer", ref rdr1); while (rdr1.Read()) { dbobj.SelectQuery("select * from CustomerLedgerTable where CustID='" + rdr1["Cust_ID"].ToString() + "' order by entrydate", ref rdr); double Bal = 0; string BalType = ""; int i = 0; while (rdr.Read()) { if (i == 0) { BalType = rdr["BalanceType"].ToString(); i++; } if (double.Parse(rdr["CreditAmount"].ToString()) != 0) { if (BalType == "Cr.") { Bal += double.Parse(rdr["CreditAmount"].ToString()); BalType = "Cr."; } else { Bal -= double.Parse(rdr["CreditAmount"].ToString()); if (Bal < 0) { Bal = double.Parse(Bal.ToString().Substring(1)); BalType = "Cr."; } else { BalType = "Dr."; } } } else if (double.Parse(rdr["DebitAmount"].ToString()) != 0) { if (BalType == "Dr.") { Bal += double.Parse(rdr["DebitAmount"].ToString()); } else { Bal -= double.Parse(rdr["DebitAmount"].ToString()); if (Bal < 0) { Bal = double.Parse(Bal.ToString().Substring(1)); BalType = "Dr."; } else { BalType = "Cr."; } } } Con.Open(); cmd = new SqlCommand("update CustomerLedgerTable set Balance='" + Bal.ToString() + "',BalanceType='" + BalType + "' where CustID='" + rdr["CustID"].ToString() + "' and Particular='" + rdr["Particular"].ToString() + "' ", Con); cmd.ExecuteNonQuery(); cmd.Dispose(); Con.Close(); } rdr.Close(); } rdr1.Close(); }
/// <summary> /// This method is used for setting the Session variable for userId and /// after that filling the required dropdowns with database values /// and also check accessing priviledges for particular user /// and generate the next ID also. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, System.EventArgs e) { try { string pass; pass = (Session["User_Name"].ToString()); } catch { Response.Redirect("../../Sysitem/ErrorPage.aspx", false); return; } if (!IsPostBack) { ColumnName = ""; View = 0; //GetNextID(); DBOperations.DBUtil dbobj = new DBOperations.DBUtil(System.Configuration.ConfigurationSettings.AppSettings["Servosms"], true); #region Check Privileges int i; string View_flag = "0", Add_Flag = "0", Edit_Flag = "0", Del_Flag = "0"; string Module = "4"; string SubModule = "11"; string[,] Priv = (string[, ])Session["Privileges"]; for (i = 0; i < Priv.GetLength(0); i++) { if (Priv[i, 0] == Module && Priv[i, 1] == SubModule) { View_flag = Priv[i, 2]; Add_Flag = Priv[i, 3]; Edit_Flag = Priv[i, 4]; Del_Flag = Priv[i, 5]; break; } } if (Add_Flag == "0" && Edit_Flag == "0" && View_flag == "0") { //string msg="UnAthourized Visit to Price Updation Page"; // dbobj.LogActivity(msg,Session["User_Name"].ToString()); Response.Redirect("../../Sysitem/AccessDeny.aspx", false); return; } if (Add_Flag == "0") { btnSubmit.Enabled = false; } //if(Add_Flag =="0" && Edit_Flag == "0") // Btnsubmit1.Enabled = false; #endregion #region Testing Purpose InventoryClass obj = new InventoryClass(); SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["Servosms"]); ArrayList arrHeaderName = new ArrayList(); ArrayList arrColName = new ArrayList(); ArrayList arrRemName = new ArrayList(); object ob = null; dbobj.ExecProc(DBOperations.OprType.Insert, "ProUpdateCustomerType", ref ob, "@Cust_ID", ""); SqlDataReader rdr = null; SqlCommand cmd; //rdr = obj.GetRecordSet("select distinct case when customertypename like 'oe%' then 'Oe' else customertypename end as customertypename from customertype order by customertypename"); rdr = obj.GetRecordSet("select distinct custtype,custtypeid from tempcustomertype order by custtypeid"); if (rdr.HasRows) { while (rdr.Read()) { string name = rdr.GetValue(0).ToString().ToLower(); name = name.Replace("/", ""); name = name.Replace(" ", ""); name = name.Replace("-", ""); if (rdr.GetValue(0).ToString().ToLower().StartsWith("ro")) { //arrColName.Add(rdr.GetValue(0).ToString().ToLower()+"lube"); //arrColName.Add(rdr.GetValue(0).ToString().ToLower()+"2t4t"); arrColName.Add(name + "lube"); arrColName.Add(name + "2t4t"); } else if (rdr.GetValue(0).ToString().ToLower().StartsWith("bazar") || rdr.GetValue(0).ToString().ToLower().StartsWith("bazzar")) { //arrColName.Add(rdr.GetValue(0).ToString().ToLower()+"lube"); //arrColName.Add(rdr.GetValue(0).ToString().ToLower()+"2t4t"); arrColName.Add(name + "lube"); arrColName.Add(name + "2t4t"); } else { //arrColName.Add(rdr.GetValue(0).ToString().ToLower()); arrColName.Add(name); } } } rdr.Close(); rdr = obj.GetRecordSet("select * from ly_ps_sale"); int n = rdr.FieldCount; //ColumnName="ly_ps_sales,month,tot_pur,pur_foc,gen_oil,grease,"; //for(int p=0,m=7;m<n;m++,p++) for (int p = 0, m = 9; m < n; m++, p++) { arrHeaderName.Add(rdr.GetName(m)); //ColumnName+=rdr.GetName(m)+","; } //ColumnName=ColumnName.Substring(0,ColumnName.Length-1); rdr.Close(); if (arrColName.Count == arrHeaderName.Count) { rdr = obj.GetRecordSet("select * from ly_ps_sale"); n = rdr.FieldCount; ColumnName = "ly_ps_sales,discription,month,tot_pur,pur_foc,gen_oil,grease,total_purchase,"; for (int p = 0, m = 9; m < n; m++, p++) { ColumnName += rdr.GetName(m) + ","; } ColumnName += "total_sales,"; ColumnName = ColumnName.Substring(0, ColumnName.Length - 1); rdr.Close(); return; } if (arrColName.Count >= arrHeaderName.Count) { for (int r = 0; r < arrColName.Count; r++) { arrRemName.Add(arrColName[r]); } for (int q = 0; q < arrHeaderName.Count; q++) { arrRemName.Remove(arrHeaderName[q]); } if (arrRemName.Count > 0) { for (int k = 0; k < arrRemName.Count; k++) { con.Open(); string name = arrRemName[k].ToString(); name = name.Replace("/", ""); name = name.Replace(" ", ""); name = name.Replace("-", ""); string str = "alter table ly_ps_sale add " + name + " float"; cmd = new SqlCommand(str, con); cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); } } } else { for (int q = 0; q < arrHeaderName.Count; q++) { arrRemName.Add(arrHeaderName[q]); } for (int q = 0; q < arrColName.Count; q++) { arrRemName.Remove(arrColName[q]); } if (arrRemName.Count > 0) { for (int k = 0; k < arrRemName.Count; k++) { con.Open(); string name = arrRemName[k].ToString(); name = name.Replace("/", ""); name = name.Replace(" ", ""); name = name.Replace("-", ""); string str = "alter table ly_ps_sale drop column " + name + ""; cmd = new SqlCommand(str, con); cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); } } } rdr = obj.GetRecordSet("select * from ly_ps_sale"); n = rdr.FieldCount; ColumnName = "ly_ps_sales,discription,month,tot_pur,pur_foc,gen_oil,grease,total_purchase,"; for (int p = 0, m = 9; m < n; m++, p++) { ColumnName += rdr.GetName(m) + ","; } ColumnName += "total_sales,"; ColumnName = ColumnName.Substring(0, ColumnName.Length - 1); rdr.Close(); #endregion } }