/// <summary> /// This method is used to Group Name in DropDownlist from CustomerType table /// Add By Viks Sharma 23.10.2012 /// </summary> public void getGroup() { try { dropGroup.Items.Clear(); dropGroup.Items.Add("Select"); dropGroup.SelectedIndex = 0; SqlDataReader SqlDtr = null; dbobj.SelectQuery("select distinct Group_Name from CustomerType order by Group_Name ", ref SqlDtr); while (SqlDtr.Read()) { if (SqlDtr["Group_Name"].ToString() != null && SqlDtr["Group_Name"].ToString() != "") { dropGroup.Items.Add(SqlDtr["Group_Name"].ToString()); } } SqlDtr.Close(); dropGroup.Items.Add("Other"); } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:Customer Type,Method: getGroup() Exception: " + ex.Message + " User: " + 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 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(); 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 to check the user is valid or not after that check permission of that user from database. /// </summary> private void btnSign_ServerClick(object sender, System.Web.UI.ImageClickEventArgs e) { CreateLogFiles.ErrorLog("Form:Login.aspx,Method: btnSign_Click, Login Type " + DropUser.SelectedItem.Text + " and Login User " + txtUserLogin.Text); PetrolPumpClass obj = new PetrolPumpClass(); try { SqlDataReader SqlDtr; string sql; string User_ID = ""; string[,] Privileges = new string[98, 6]; /****add-bhal****/ Session["CurrentDate"] = txtSetDate.Text.ToString(); #region Check for Valid User string pwd = ""; string epassword = ""; sql = "select Password from User_Master where LoginName='" + txtUserLogin.Text + "'"; SqlDtr = obj.GetRecordSet(sql); if (SqlDtr.Read()) { pwd = MySecurity.MySecurity.Decrypt(SqlDtr.GetValue(0).ToString(), "!@#$%^"); if (txtPasswd.Text == pwd) { epassword = SqlDtr.GetValue(0).ToString(); SqlDtr.Close(); } else { RMG.MessageBox.Show("Invalid User Login Name or Password"); return; } } else { RMG.MessageBox.Show("Invalid User Login Name or Password"); return; } SqlDtr.Close(); // Calls the method contactServer by passing the selected date to set the system date as a selected date. string ss = MySecurity.MySecurity.contactServer("[CD]" + convertDate(txtSetDate.Text)); // contactServer("[CD]"+convertDate(TxtDateFrom.Text)); #region get the message from Organisation table and put into session to display in all the invoices dbobj.SelectQuery("Select Message from organisation where CompanyID = 1001", ref SqlDtr); if (SqlDtr.Read()) { Session["Message"] = SqlDtr.GetValue(0).ToString(); } else { Session["Message"] = ""; } SqlDtr.Close(); #endregion #region get the VAT_Rate from Organisation table and put into session to access in Sales and Purchase Invoice. dbobj.SelectQuery("Select VAT_Rate from organisation where CompanyID = 1001", ref SqlDtr); if (SqlDtr.Read()) { Session["VAT_Rate"] = SqlDtr.GetValue(0).ToString(); } else { Session["VAT_Rate"] = ""; } SqlDtr.Close(); #endregion #region get the EntryTax from Organisation table and put into session to access in Sales and Purchase Invoice. dbobj.SelectQuery("Select Entrytax from organisation where CompanyID = 1001", ref SqlDtr); if (SqlDtr.Read()) { Session["Entrytax"] = SqlDtr.GetValue(0).ToString(); } else { Session["Entrytax"] = ""; } SqlDtr.Close(); #endregion #region select the user id ,password compare and stored in a session variable. sql = "select UserID, LoginName,password,Role_Name from User_Master um, Roles r where um.role_ID=r.role_ID and um.LoginName='" + txtUserLogin.Text + "' and password='******' and r.Role_ID=(select Role_ID from Roles where Role_Name='" + DropUser.SelectedItem.Value + "')"; SqlDtr = obj.GetRecordSet(sql); if (SqlDtr.Read()) { User_ID = SqlDtr.GetValue(0).ToString(); Session["User_ID"] = User_ID; //string sss=SqlDtr.GetValue(1).ToString(); Session["User_Name"] = (SqlDtr.GetValue(1).ToString()); //string sss1=(Session["User_Name"].ToString()); Cache["User_Name"] = (SqlDtr.GetValue(1).ToString()); Session["PASSWORD"] = SqlDtr.GetValue(2).ToString(); Session["User_Type"] = SqlDtr.GetValue(3).ToString(); SqlDtr.Close(); } else { RMG.MessageBox.Show("Invalid User Login Name or Password"); return; } SqlDtr.Close(); #endregion #endregion if (User_ID != "") { #region Get The User Permission sql = "select * from Privileges where User_ID='" + User_ID + "'"; SqlDtr = obj.GetRecordSet(sql); for (int i = 0; SqlDtr.Read(); i++) { for (int j = 0; j < 6; j++) { Privileges[i, j] = SqlDtr.GetValue(j + 1).ToString(); } } SqlDtr.Close(); //Session["Privileges"]=Privileges; Cache["Privileges"] = Privileges; #endregion Response.Redirect("HomePage.aspx", false); } else { RMG.MessageBox.Show("Invalid User Login Name or Password"); return; } txtUserLogin.Enabled = true; txtPasswd.Enabled = true; } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:Login.aspx,Method: btnSign_Click, Login Type " + DropUser.SelectedItem.Text + " EXCEPTION " + ex.ToString() + " and Login User " + txtUserLogin.Text); } }
/// <summary> /// This method is used to update the record in edit time who select from dropdownlist. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEdit_Click(object sender, System.EventArgs e) { if (dropLedgerName.SelectedIndex == 0) { MessageBox.Show("Please select Ledger Name"); fetchGroup(); return; } try { string SubGrp = ""; string Group = ""; // Check & Fetch The sub Group if (DropSub.SelectedIndex == 0) { MessageBox.Show("Please select Sub Group"); fetchGroup(); return; } else { if (DropSub.SelectedItem.Text == "Other") { if (TxtSub.Text.Trim() == "") { MessageBox.Show("Please specify Other Sub Group"); TxtSub.Enabled = true; fetchGroup(); return; } else { SubGrp = TxtSub.Text.Trim(); } } else { SubGrp = DropSub.SelectedItem.Text.Trim(); } } // Check & Fetch The Group if (txtTempGrp.Value == "Select") { MessageBox.Show("Please select Group"); fetchGroup(); return; } else { if (txtTempGrp.Value == "Other") { if (TxtGroup.Text.Trim() == "") { MessageBox.Show("Please specify Other Group"); TxtGroup.Enabled = true; fetchGroup(); DropGroup.SelectedIndex = DropGroup.Items.IndexOf(DropGroup.Items.FindByText(txtTempGrp.Value)); return; } else { Group = TxtGroup.Text.Trim(); } } else { //Group = DropGroup.SelectedItem.Text.Trim(); Group = txtTempGrp.Value; } } SqlDataReader SqlDtr = null; if (Ledger_Name != TxtLedger.Text.Trim()) { dbobj.SelectQuery("select * from ledger_master where ledger_name='" + TxtLedger.Text.Trim() + "'", ref SqlDtr); if (SqlDtr.HasRows) { MessageBox.Show("Ledger Name '" + TxtLedger.Text + "' is Allready Exist"); return; } SqlDtr.Close(); } string ledgname = ""; string nature = ""; double Op_bal = 0; string bal_type = ""; ledgname = TxtLedger.Text.Trim(); Op_bal = System.Convert.ToDouble(TxtOpeningBal.Text.ToString()); bal_type = DropBalType.SelectedItem.Text.Trim(); if (RadioAsset.Checked) { nature = "Assets"; } else if (RadioLiab.Checked) { nature = "Liabilities"; } else if (RadioExp.Checked) { nature = "Expenses"; } else { nature = "Income"; } string ledgname1 = ""; ledgname1 = dropLedgerName.SelectedItem.Text.ToString(); string[] strArr = ledgname1.Split(new char[] { ':' }, ledgname1.Length); LedgerModel ledger = new LedgerModel(); ledger.SubGroupName = SubGrp; ledger.GroupNature = nature; ledger.GroupName = Group; ledger.LedgerName = ledgname; //ledger.SubGroupID = subgrpid; ledger.LedgerID = strArr[1].Trim(); ledger.OpeningBalance = TxtOpeningBal.Text.ToString(); ledger.BalanceType = DropBalType.SelectedItem.Text.Trim(); string id = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseUri); var myContent = JsonConvert.SerializeObject(ledger); var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var response = client.PostAsync("api/LedgerController/UpdateLedger", byteContent).Result; if (response.IsSuccessStatusCode) { string responseString = response.Content.ReadAsStringAsync().Result; id = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(responseString); } } if (id != null && !id.Equals(strArr[1])) { MessageBox.Show("Ledger Name is already exist for selected Sub Group "); fetchGroup(); DropGroup.SelectedIndex = DropGroup.Items.IndexOf(DropGroup.Items.FindByText(Group)); return; } MessageBox.Show("Ledger Updated"); CreateLogFiles.ErrorLog("Form:Ledger Creation,Method:btnEdit_Click Ledger ID " + strArr[1].Trim() + " of " + ledgname + " Updated. User: "******"Form:Ledger Creation,Method:btnEdit_Click Exception: " + ex.Message + " User: " + uid); } }
/// <summary> /// This method is used to save or update the user details in user master table with the help of /// ProUserMasterUpdate and ProUserMasterEntry stored procedure. /// </summary> protected void btnUpdate_Click(object sender, System.EventArgs e) { EmployeeClass obj = new EmployeeClass(); int x = 0; try { #region check the username is exist or not? dbobj.ExecuteScalar("select count(*) from user_master where loginname='" + txtLoginName.Text.Trim() + "'", ref x); if (x > 0) { if (dropUserID.Visible) { SqlDataReader SqlDtr = null; string UserId = ""; dbobj.SelectQuery("Select UserID from user_master where loginname='" + txtLoginName.Text.Trim() + "'", ref SqlDtr); if (SqlDtr.Read()) { UserId = SqlDtr.GetValue(0).ToString().Trim(); } SqlDtr.Close(); if (!dropUserID.SelectedItem.Text.Trim().Equals(UserId)) { RMG.MessageBox.Show("User " + txtLoginName.Text + " already exists"); return; } } else { RMG.MessageBox.Show("User " + txtLoginName.Text + " already exists"); return; } } #endregion string Name = ""; Name = txtFName.Text; Name += " " + txtMName.Text; Name += " " + txtLName.Text; Name = Name.Trim(); obj.Login_Name = txtLoginName.Text.ToString(); obj.Password = Encrypt(txtPassword.Text.ToString(), "!@#$%^"); //obj.User_Name=txtFName.Text.ToString()+" "+txtMName.Text.ToString()+" "+txtLName.Text.ToString(); obj.User_Name = Name; obj.Role_Name = DropRole.SelectedItem.Value; if (dropUserID.Visible) { obj.User_ID = dropUserID.SelectedItem.Value; //call the procedure ProUserMasterUpdate to update the required user details in user master table. obj.UpdateUserMaster(); CreateLogFiles.ErrorLog("Form:User_Profile.aspx,Method:brnUpdate_Click. User ID" + obj.User_ID + " Updated. User: "******"User Profile Updated"); } else { obj.User_ID = lblUserID.Text.ToString(); //call the procedure ProUserMasterEntry to insert the user details in user master table. obj.InsertUserMaster(); CreateLogFiles.ErrorLog("Form:User_Profile.aspx,Method:brnUpdate_Click. New User With ID " + obj.User_ID + " Created. User: "******"User Profile Created"); } Clear(); GetNextUserID(); lblUserID.Visible = true; btnEdit.Visible = true; dropUserID.Visible = false; } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:User_Profile.aspx,Method:Page_load EXCEPTION: " + ex.Message + " " + uid); } }
/// <summary> /// This method returns the parties (i.e. Customer and Vendor names) in the form array to compare the Ledger Name not equals to Parties Names. /// </summary> /// <returns></returns> public object[] getParties() { try { SqlDataReader SqlDtr = null; dbobj.SelectQuery("Select Cust_Name from Customer order by Cust_Name", ref SqlDtr); while (SqlDtr.Read()) { al.Add(SqlDtr["Cust_Name"].ToString()); } SqlDtr.Close(); dbobj.SelectQuery("Select Supp_Name from Supplier order by Supp_Name", ref SqlDtr); while (SqlDtr.Read()) { al.Add(SqlDtr["Supp_Name"].ToString()); } SqlDtr.Close(); return(al.ToArray()); } catch (Exception ex) { CreateLogFiles.ErrorLog("Form:Ledger Creation,Method:getParties() Exception: " + ex.Message + " User: " + uid); return(null); } }