public static bool AuthenticateUser(string username, string password) { // ConfigurationManager class is in System.Configuration namespace string CS = ConnectSQL.GetConnectionString(); // SqlConnection is in System.Data.SqlClient namespace using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("spAuthenticateUser", con); cmd.CommandType = CommandType.StoredProcedure; // FormsAuthentication is in System.Web.Security string EncryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1"); // SqlParameter is in System.Data namespace SqlParameter paramUsername = new SqlParameter("@UserName", username); SqlParameter paramPassword = new SqlParameter("@Password", EncryptedPassword);//we are not using authentiacated password ,use EncryptedPassword to use authenticated password cmd.Parameters.Add(paramUsername); cmd.Parameters.Add(paramPassword); con.Open(); int ReturnCode = (int)cmd.ExecuteScalar(); return(ReturnCode == 1); } }
//public void LoadData() //{ // string sql = "select wodate,shift,modelcode,count(case when status ='G' then 1 end)as OK,count(case when status ='N' then 1 end)as NG,count(status) as Total,empname from tb_datachecked where wodate = '"+DateTime.Now.ToString("yyyyMMdd")+"' group by wodate,shift,modelcode,empname"; // DataTable dt = conn.GetDataTable(sql); // dgvData.DataSource = dt; //} private void frm_InputData_Load(object sender, EventArgs e) { string servername_ = tool.Read(pathfile, "DataBase", "Server"); string database_ = tool.Read(pathfile, "DataBase", "DataBase"); string user_ = tool.Read(pathfile, "DataBase", "User"); conn = new ConnectSQL(servername_, database_, user_); txtWorkDate.Text = DateTime.Now.ToString("yyyy.MM.dd"); txtLine.Text = line; txtShift.Text = shift; linecode = tool.Read(pathfile, "LineConfig", "LineCode"); linename = tool.Read(pathfile, "LineConfig", "LineName"); frm = this; Status(false); btnSave.Visible = false; cboDef.Visible = false; //txtEmployee.Enabled = true; //txtProduct.Enabled = true; LoadData(); GetAllControls(this); foreach (Control c in ControlList) { tool.TranslateControl(this, c, tool.GetLanguage(tool.Read(pathfile, "Infor", "Language"))); } lbOK.Location = new Point(5, lbOK.Location.Y); lbMix.Location = new Point(5, lbMix.Location.Y); lbDeff.Location = new Point(5, lbDeff.Location.Y); lbTotal.Location = new Point(5, lbTotal.Location.Y); txtEmployee.Focus(); }
internal List <int> GetPartnerIds(int FileId) { List <int> PartnerIds = new List <int>(); using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("Select UserId From FilePartners Where FileId=@FileId AND Isdeleted=0", con); cmd.Parameters.AddWithValue("@FileId", FileId); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { PartnerIds.Add(Convert.ToInt32(rdr[0])); } } } catch (Exception) { throw; } finally { con.Close(); } } return(PartnerIds); }
internal void GenerateOTP(List <int> GetAllPartnerId, int RequestId) { foreach (var PartnerId in GetAllPartnerId) { using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("SpPartnerOtpInsert", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RequestId", RequestId); cmd.Parameters.AddWithValue("@OTP", RandomGenerate.Otp); cmd.Parameters.AddWithValue("@PartnerId", PartnerId); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { con.Close(); } } } }
internal int GenerateRequest(int FileId, int UserId) { int RequestId = 0; using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("SpFileRequest", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FileId", FileId); cmd.Parameters.AddWithValue("@UserId", UserId); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { RequestId = Convert.ToInt32(rdr["RESPONSE"]); } } } catch (Exception) { throw; } finally { con.Close(); } } return(RequestId); }
public bool UserDisableEnable(string Email) { using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("SpUserEnableDisable", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Email", Email); cmd.ExecuteNonQuery(); return(true); } catch { return(false); } finally { con.Close(); } } }
public List <User> ListUsers() { List <User> _listUsers = new List <User>(); SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString()); try { con.Open(); SqlCommand cmd = new SqlCommand("select EmailID,Rowstatus from inz_USERS", con); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { User _user = new User(); _user.EmailID = rdr["EmailID"].ToString(); _user.Rowstatus = Convert.ToChar(rdr["Rowstatus"]); _listUsers.Add(_user); } return(_listUsers); } catch { return(_listUsers); } finally { con.Close(); } }
internal string GetFileName(int FileId) { string Filename = "NIL"; using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("select [FileName] from inz_Post Where PostID=@FileId AND IsDeleted=0", con); cmd.Parameters.AddWithValue("@FileId", FileId); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { Filename = rdr["FileName"].ToString(); } } } catch (Exception) { throw; } finally { con.Close(); } } return(Filename); }
public static int GetUserID(string USername) { int Userid = 0; using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("select UserId from inz_USERS Where Username=@Username", con); cmd.Parameters.AddWithValue("@Username", USername); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Userid = (int)rdr["UserId"]; } return(Userid); } catch (Exception) { throw; } finally { con.Close(); } } }
//select OTP from RequestTransaction where RequestId=@RequestId AND PartnerId=@PartnerId public int GetOtp(int RequestId, int PartnerId) { int Otp = 0; using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("select OTP from RequestTransaction where RequestId=@RequestId AND PartnerId=@PartnerId", con); cmd.Parameters.AddWithValue("@RequestId", RequestId); cmd.Parameters.AddWithValue("@PartnerId", PartnerId); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { Otp = Convert.ToInt32(rdr["Otp"]); } } } catch (Exception) { throw; } finally { con.Close(); } } return(Otp); }
internal static int GetUserIDByEmailId(string EmailID) { int Userid = 0; using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("select UserId from inz_USERS Where EmailID=@EmailID", con); cmd.Parameters.AddWithValue("@EmailID", EmailID); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Userid = (int)rdr["UserId"]; } return(Userid); } catch { return(Userid); } finally { con.Close(); } } }
private void fHomePages_Load(object sender, EventArgs e) { Account = ConnectSQL.ExcuteQuery("Select IDStaff, Status from Account"); for (int i = 0; i < Account.Rows.Count; i++) { if (Account.Rows[i][1].ToString() == "1") { ReturnIDAccount = Account.Rows[i][0].ToString(); } } Bill = ConnectSQL.ExcuteQuery("select distinct YEAR(date) from Bill"); for (int i = 0; i < Bill.Rows.Count; i++) { if (Bill.Rows[0][0] != DBNull.Value) { cbYear.Items.Add(Bill.Rows[i][0].ToString()); } } cbYear.SelectedIndex = 0; cMonth.Checked = true; chartMonth.ChartAreas[0].AxisX.Minimum = 1; chartMonth.ChartAreas[0].AxisX.Maximum = 12; timer1.Start(); CreateChartMonth(); CreateChartQuy(); CreateChartProduct(); CreateChartCustomer(); rProduct.Checked = true; chartCustomer.Visible = false; }
public static bool UserRegister(User _user) { string CS = ConnectSQL.GetConnectionString(); // SqlConnection is in System.Data.SqlClient namespace using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("spRegisterUser", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter username = new SqlParameter("@UserName", _user.Username); // FormsAuthentication calss is in System.Web.Security namespace string encryptedPassword = FormsAuthentication. HashPasswordForStoringInConfigFile(_user.Password, "SHA1"); SqlParameter password = new SqlParameter("@Password", encryptedPassword); SqlParameter email = new SqlParameter("@Email", _user.EmailID); SqlParameter Category = new SqlParameter("@Category", _user.Category); cmd.Parameters.Add(username); cmd.Parameters.Add(password); cmd.Parameters.Add(email); cmd.Parameters.Add(Category); con.Open(); int ReturnCode = (int)cmd.ExecuteScalar(); return(ReturnCode == 1); } }
internal string GetEmailbyPartnerId(string PartnerId) { string EmailId = ""; using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("select EmailID from inz_USERS Where UserID=@PartnerId", con); cmd.Parameters.AddWithValue("@PartnerId", PartnerId); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { EmailId = (string)rdr["EmailID"]; } return(EmailId); } catch { throw; } finally { con.Close(); } } }
public ActionResult Index(HttpPostedFileBase _File) { byte[] File = new byte[_File.ContentLength]; Files FileModel = new Files(); FileModel.Document = File; FileModel.Name = _File.FileName; _File.InputStream.Read(FileModel.Document, 0, _File.ContentLength); using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO Movies ([File],FileId) VALUES (@File,@FileId)", con); cmd.Parameters.AddWithValue("@File", FileModel.Document); cmd.Parameters.AddWithValue("@FileId", GetFileId()); cmd.ExecuteNonQuery(); } catch (System.Exception) { throw; } finally { con.Close(); } } return(View()); }
private int GetFileId() { int FileId = 0; using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("SELECT TOP 1 FileID from inz_file Order by FileID DESC", con); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { FileId = (int)rdr[0]; } } } catch (System.Exception) { throw; } finally { con.Close(); } } return(FileId); }
public FileResponse SaveFile(int UserId, int FileId) { FileResponse fileResponse; using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("FileSave", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FileId", FileId); cmd.Parameters.AddWithValue("@UserId", UserId); int Response = int.Parse(cmd.ExecuteScalar().ToString()); if (Response == (int)FileStatus.Sucess) { fileResponse = new FileResponse { Message = "Partner added sucessfully", Status = FileStatus.Sucess }; } else if (Response == (int)FileStatus.Exists) { fileResponse = new FileResponse { Message = "Partner already exists", Status = FileStatus.Exists }; } else { fileResponse = new FileResponse { Message = "Some thing went wrong", Status = FileStatus.Error }; } } catch (Exception ex) { fileResponse = new FileResponse { Message = ex.Message.ToString(), Status = FileStatus.Error }; } finally { con.Close(); } } return(fileResponse); }
public static List <User> UserAllUser(int FileId) { List <User> userlist = new List <User>(); SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString()); try { con.Open(); SqlCommand cmd = new SqlCommand("SpFileAccess", con); cmd.Parameters.AddWithValue("@FileId", FileId); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { User user = new User(); user.UserID = (int)rdr["UserID"]; user.Username = rdr["Username"].ToString(); user.Rowstatus = Convert.ToChar(rdr["Rowstatus"]); userlist.Add(user); } } else { rdr.Dispose(); cmd.Dispose(); cmd = new SqlCommand("select UserID,Username,Rowstatus from inz_USERS", con); rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { User user = new User(); user.UserID = (int)rdr["UserID"]; user.Username = rdr["Username"].ToString(); user.Rowstatus = Convert.ToChar(rdr["Rowstatus"]); userlist.Add(user); } } } return(userlist); } catch { return(userlist); } finally { con.Close(); } }
public static int CheckRole(string username) { ConnectSQL cnts = new ConnectSQL(); int roleID = 3; DataTable dbRole = cnts.GetTableWithCommandText("select * from tblAdministrators A join tblRole R ON A.ROLL = R.ROLEID where username='******'"); if (dbRole.Rows.Count > 0) { roleID = Convert.ToInt32(dbRole.Rows[0]["ROLEID"].ToString()); } return(roleID); }
public static void Main(string[] args) { var conn = new ConnectSQL(); ConnectSQL.Connect("mysql-Username", "mysql-Password"); var scrape = new scrape(); var results = scrape.scraper(); foreach (var stock in results) { Console.WriteLine(stock); } }
private void frm_EditDeff_Load(object sender, EventArgs e) { string servername_ = tool.Read(pathfile, "DataBase", "Server"); string database_ = tool.Read(pathfile, "DataBase", "DataBase"); string user_ = tool.Read(pathfile, "DataBase", "User"); conn = new ConnectSQL(servername_, database_, user_); frm = this; if (keycode != "") { string sql = "select Wodate,shift,keycode,modelcode,goodqty,defqty,mixqty,total,starttime,endtime,linename,empname from tb_datachecked where keycode='" + keycode + "'"; DataTable dt = conn.GetDataTable(sql); if (dt.Rows.Count == 1) { try { txtdef.Text = dt.Rows[0]["defqty"].ToString(); int.TryParse(txtdef.Text, out deftmp); txtempname.Text = dt.Rows[0]["empname"].ToString(); txtendtime.Text = dt.Rows[0]["endtime"].ToString(); txtgood.Text = dt.Rows[0]["goodqty"].ToString(); txtkeycode.Text = dt.Rows[0]["keycode"].ToString(); txtlinename.Text = dt.Rows[0]["linename"].ToString(); txtmix.Text = dt.Rows[0]["mixqty"].ToString(); txtmodelcode.Text = dt.Rows[0]["modelcode"].ToString(); txtshift.Text = dt.Rows[0]["shift"].ToString(); txtstarttime.Text = dt.Rows[0]["starttime"].ToString(); txttotal.Text = dt.Rows[0]["total"].ToString(); int.TryParse(txttotal.Text, out totaltmp); txtwodate.Text = dt.Rows[0]["wodate"].ToString(); } catch { frm_MessageWarning warning = new frm_MessageWarning(); warning.index = 6; warning.ShowDialog(); } } } GetAllControls(this); foreach (Control c in ControlList) { tool.TranslateControl(this, c, tool.GetLanguage(tool.Read(pathfile, "Infor", "Language"))); } }
private void btnnext_Click(object sender, EventArgs e) { try { string conString = "Data Source=" + txtserver.Text + ";Database=" + cbbDatabase.Text + ";User Id=" + txtUsername.Text + ";Password="******"; pooling=false"; if (!ConnectSQL.CheckConnect(conString)) { MessageBox.Show("Connect Fail"); return; } else { if (chkSavepass.Checked) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter writer = XmlWriter.Create(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\configDsc.xml", settings); writer.WriteStartDocument(); writer.WriteComment("This file is generated by the program."); writer.WriteStartElement("Root"); writer.WriteStartElement("LVConfig"); writer.WriteElementString("ServerName", txtserver.Text); writer.WriteElementString("UserName", txtUsername.Text); writer.WriteElementString("Password", txtPassword.Text); writer.WriteElementString("Database", cbbDatabase.Text); writer.WriteElementString("ChkSave", chkSavepass.Checked.ToString()); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } FrmListData frmListTable = new FrmListData(); this.Hide(); frmListTable.Show(); } } catch (Exception es) { MessageBox.Show("Connect Fail!"); } }
public ActionResult Login(string server, string port, string username, string password) { if (string.IsNullOrEmpty(server) || string.IsNullOrEmpty(port) || string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { ViewBag.Messengerr = "Thông tin nhập vào không đầy đủ"; return(View()); } loginData = new LoginData(server, port, username, password); ConnectSQL connectSQL = new ConnectSQL(); string result = connectSQL.Login(loginData); if (result.Equals("OK")) { Session["admin"] = loginData; return(RedirectToAction("Index")); } ViewBag.Messengerr = result; return(View()); }
internal void DeleteRequest(int RequestId) { using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("UPDATE RequestFile SET IsDeleted=1 Where RequestId=@RequestId", con); cmd.Parameters.AddWithValue("@RequestId", RequestId); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { con.Close(); } } }
internal void RestoreRequestTransactions(int RequestId) { using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("UPDATE RequestTransaction SET IsOTPVerified=0,OTP=@OTP Where RequestId=@RequestId UPDATE RequestFile SET IsDeleted=0 Where RequestId=@RequestId", con); cmd.Parameters.AddWithValue("@RequestId", RequestId); cmd.Parameters.AddWithValue("@OTP", RandomGenerate.Otp); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { con.Close(); } } }
private void frm_Main_Load(object sender, EventArgs e) { string servername_ = tool.Read(pathfile, "DataBase", "Server"); string database_ = tool.Read(pathfile, "DataBase", "DataBase"); string user_ = tool.Read(pathfile, "DataBase", "User"); conn = new ConnectSQL(servername_, database_, user_); frm = this; fromdate = dtpFrom.Value.ToString("yyyyMMdd"); todate = dtpTo.Value.ToString("yyyyMMdd"); cboShift.SelectedIndex = 0; LoadData(); //GetLotNumber(fromdate, todate); txtLine.Text = tool.Read(pathfile, "LineConfig", "LineName").ToUpper(); GetAllControls(this); foreach (Control c in ControlList) { tool.TranslateControl(this, c, tool.GetLanguage(tool.Read(pathfile, "Infor", "Language"))); } lbUser.Text = user__; txtCheck.Focus(); }
public static List <User> getAllUsers() { List <User> userlist = new List <User>(); using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("select * from inz_USERS Where Rowstatus='A'", con); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { User user = new User(); user.UserID = (int)rdr["UserID"]; user.Username = rdr["Username"].ToString(); user.Rowstatus = Convert.ToChar(rdr["Rowstatus"]); user.EmailID = rdr["EmailID"].ToString(); userlist.Add(user); } } return(userlist); } catch (Exception) { throw; } finally { con.Close(); } } }
public bool FileUserAccess(int FileId, int UserId) { using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("select PartnerId from FilePartners Where UserId=@UserId AND FileId=@FileId AND IsDeleted=0", con); cmd.Parameters.AddWithValue("@UserId", UserId); cmd.Parameters.AddWithValue("@FileId", FileId); SqlDataReader rdr = cmd.ExecuteReader(); return(rdr.HasRows); } catch (Exception) { throw; } finally { con.Close(); } } }
internal void AuthenticateOTP(int RequestId, int UserId, string OTP) { using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); SqlCommand cmd = new SqlCommand("UPDATE RequestTransaction Set IsOTPVerified=1 Where PartnerId=@PartnerId AND RequestId=@RequestId AND OTP=@OTP", con); cmd.Parameters.AddWithValue("@RequestId", RequestId); cmd.Parameters.AddWithValue("@PartnerId", UserId); cmd.Parameters.AddWithValue("@OTP", OTP); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { con.Close(); } } }
public List <User> GetPartnersbyFileId(int FileId) { using (SqlConnection con = new SqlConnection(ConnectSQL.GetConnectionString())) { try { con.Open(); List <User> ListUser = new List <User>(); SqlCommand cmd = new SqlCommand("GetPartners", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FileId", FileId); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { User userObj = new User() { Username = rdr["Username"].ToString(), EmailID = rdr["EmailID"].ToString(), Rowstatus = int.Parse(rdr["Isdeleted"].ToString()) == 0?'A':'D', UserID = int.Parse(rdr["UserId"].ToString()) }; ListUser.Add(userObj); } return(ListUser); } catch (Exception) { throw; } finally { con.Close(); } } }