public List <string> GetCheckedNodes(TreeNodeCollection nodes) { List <string> nodelist = new List <string>(); if (nodes == null) { return(nodelist); } foreach (TreeNode childNodes in nodes) { if (childNodes.IsSelected) { Userjob uj = new Userjob(); uj.userID = get_userIdForsetjob; uj.JobId = Convert.ToInt32(childNodes.Tag); uj.UserJobStartDate = PublicVariable.TodayDate; uj.Status = 1; // Control that the user does not take a job twice int GetJobId = Convert.ToInt32(childNodes.Tag); var query = (from Usj in database.Userjobs where Usj.userID == this.get_userIdForsetjob where Usj.JobId == GetJobId select Usj).ToList(); // Warning / controlling the possession of another person's job var query_job = (from UJob in database.Userjobs where UJob.JobId == GetJobId where UJob.Status == 1 select UJob).ToList(); if (query_job.Count > 0) { if (MessageBox.Show("This job is in the possession of someone else, will you continue?", "Attention ", MessageBoxButtons.YesNo) == DialogResult.No) { break; } } if (query.Count == 0) { database.Userjobs.Add(uj); database.SaveChanges(); MessageBox.Show("The new job was successfully assigned to the user"); this.Close(); } else { MessageBox.Show("Note, this user has already had this job."); // با وجود سابقه داشتن شغل باز هم شغل تخصیص مییابد database.Userjobs.Add(uj); database.SaveChanges(); MessageBox.Show("The new job was successfully assigned to the user"); this.Close(); } } nodelist.AddRange(GetCheckedNodes(childNodes.Nodes)); } return(nodelist); }
private void btn_sabt_Click(object sender, EventArgs e) { try { ///Insert remember into database using Entity Framework syntaxes /// Remember R = new Remember(); R.subject = txtSubject.Text.Trim(); R.matn = txtMatn.Text.Trim(); R.createDate = lbl_date.Text.Trim(); R.DateRemember = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(persianDateTimePickerRemember.Value.Year.ToString() + "/" + persianDateTimePickerRemember.Value.Month.ToString() + "/" + persianDateTimePickerRemember.Value.Day.ToString())); R.IsRead = 1; R.UserId = 1; db.Remembers.Add(R); db.SaveChanges(); MessageBox.Show("A new reminder was recorded."); this.Close(); } catch { MessageBox.Show("There was a problem recording the reminder. Please try again"); } }
private void btn_createSupport_Click(object sender, EventArgs e) { if (txt_subject.Text.Trim() == "" || txt_description.Text.Trim() == "") { MessageBox.Show("Please enter the required values"); return; } try { support s = new support(); s.support_subject = txt_subject.Text.Trim(); s.support_description = txt_description.Text.Trim(); s.userId = PublicVariable.gUserId; s.support_date = PublicVariable.TodayDate; database.supports.Add(s); database.SaveChanges(); MessageBox.Show("Your request has been sent successfully."); this.Close(); } catch { MessageBox.Show("There is a problem with the server."); return; } }
private void btn_delDraft_Click(object sender, EventArgs e) { try { int item = dgv_ShowDraft.SelectedCells.Count; if (item >0) { if (MessageBox.Show("Are you sure you want to delete this draft?", "Delete draft", MessageBoxButtons.YesNo) == DialogResult.Yes) { int get_letterID = Convert.ToInt32(dgv_ShowDraft.CurrentRow.Cells["LetterID"].Value); var deleteQuery = (from L in database.Letters where L.LetterId == get_letterID select L).SingleOrDefault(); database.Letters.Remove(deleteQuery); database.SaveChanges(); MessageBox.Show("The letter was successfully removed from the draft."); ShowDraft(searchCondition()); } } } catch { MessageBox.Show("There are problems with the server. try again"); } }
private void ReadingToolStripMenuItem_Click(object sender, EventArgs e) { /// Commands for displaying letters StiReport report = new StiReport(); report.Load(System.AppDomain.CurrentDomain.BaseDirectory + "\\Reports\\RefferenceReport.mrt"); report.Dictionary.Variables["reportDate"].Value = PublicVariable.TodayDate; //report.Dictionary.Variables["to"].Value = PublicVariable.gUserFirstName + " " + PublicVariable.gUserFamilyName; report["@LetterID"] = dgv_showAllRecievedReferenceLetters.CurrentRow.Cells["LetterID"].Value; report["@userID"] = PublicVariable.gUserId; report.Compile(); report.Render(); report.Show(); /////Commands to convert letters to read int GetLetterID = Convert.ToInt32(dgv_showAllRecievedReferenceLetters.CurrentRow.Cells["LetterID"].Value); var query_update = (from RL in database.ReferenceLetters where RL.UserID_Reciever == PublicVariable.gUserId where RL.LetterId == GetLetterID where RL.ReadType == 1 select RL).ToList(); if (query_update.Count > 0) // Checking that the letter has not been read, if any, does not require an update { var query_updateReadtype = (from RL in database.ReferenceLetters where RL.UserID_Reciever == PublicVariable.gUserId where RL.LetterId == GetLetterID where RL.ReadType == 1 select RL).SingleOrDefault(); query_updateReadtype.ReadType = 2; database.SaveChanges(); ShowAllRecievedReferenceLetter(searchCondition()); } }
private void btn_sabt_Click(object sender, EventArgs e) { ////Control of empty values if (txt_newPassword.Text.Trim() == "" || txt_newPasswordAgain.Text.Trim() == "") { MessageBox.Show("Please enter the requested values"); return; } ///Check that the password is the same and repeat if (txt_newPassword.Text.Trim() == txt_newPasswordAgain.Text.Trim()) { /////////////hashing password SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider(); Byte[] B1; Byte[] B2; B1 = UTF8Encoding.UTF8.GetBytes(txt_newPassword.Text.Trim()); B2 = SHA256.ComputeHash(B1); string HashedPassword = BitConverter.ToString(B2); var query_updatePassword = (from U in database.Users where U.userID == this.getUserId select U).SingleOrDefault(); query_updatePassword.Password = HashedPassword; database.SaveChanges(); MessageBox.Show("Password changed successfully."); this.Close(); } else { MessageBox.Show("The new password is not the same as repeating it!!"); return; } }
private void btn_sabt_Click(object sender, EventArgs e) { if (txt_subject.Text.Trim() == "" || txt_description.Text.Trim() == "" || txt_timeDone.Text.Trim() == "") { MessageBox.Show("Please fill in the required values."); return; } try { work W = new work(); W.work_subject = txt_subject.Text.Trim(); W.work_description = txt_description.Text.Trim(); W.userID = PublicVariable.gUserId; W.timeDone = Convert.ToInt32(txt_timeDone.Text.Trim()); W.dateDone = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(persianDateTimePicker_done.Value.Year.ToString() + "/" + persianDateTimePicker_done.Value.Month.ToString() + "/" + persianDateTimePicker_done.Value.Day.ToString())); W.jobID = Convert.ToInt32(cmb_request.SelectedValue); database.works.Add(W); database.SaveChanges(); MessageBox.Show("Your information was successfully registered."); ClearForm(); } catch { MessageBox.Show("There was a problem with the server. try again."); } ShowWorks(searchCondition()); }
private List <string> GetCheckedNode(TreeNodeCollection nodes) { List <string> nodelist = new List <string>(); if (nodes == null) { return(nodelist); } foreach (TreeNode childnode in nodes) { if (childnode.Checked) { /// Registration of access s.92 UsereAccess UA = new UsereAccess(); UA.userID = this.GetUserID; UA.SystemPardID = Convert.ToInt32(childnode.Tag); var query = from UAccess in database.UsereAccesses where UAccess.userID == this.GetUserID where UAccess.SystemPardID == UA.SystemPardID select UAccess; var result = query.ToList(); if (result.Count == 0) /// Did he already have this access? { database.UsereAccesses.Add(UA); database.SaveChanges(); } } else if (childnode.Checked == false && (childnode.Tag) != "1") ///Get access { try { database.Sp_DeleteUserAccess(this.GetUserID, Convert.ToInt32(childnode.Tag)); database.SaveChanges(); } catch { MessageBox.Show("There was a problem with the server. Try again."); } } nodelist.AddRange(GetCheckedNode(childnode.Nodes)); } return(nodelist); }
private void dgv_ShowRemember_DoubleClick(object sender, EventArgs e) { MessageBox.Show(dgv_ShowRemember.CurrentRow.Cells["matn"].Value.ToString(), dgv_ShowRemember.CurrentRow.Cells["subject"].Value.ToString()); try { int getrememberID = Convert.ToInt32(dgv_ShowRemember.CurrentRow.Cells["RememberId"].Value); //////Update by linq to entity //////select * from Remember where rememberID = getrememberID var updateQuery = (from R in database.Remembers where R.RememberID == getrememberID select R).SingleOrDefault(); updateQuery.IsRead = 2; database.SaveChanges(); ShowRemember(searchCondition()); } catch { } }
private void btn_ok_Click(object sender, EventArgs e) //s.28 { try { if (this.formType == 1) { if (txt_jobName.Text.Trim() == "") { MessageBox.Show("Enter the job title."); return; } Job j = new Job(); j.jobsName = txt_jobName.Text.Trim(); j.jobsDetail = txt_jobDetail.Text.Trim(); j.jobsLevel = this.Get_jobLevel; j.DetermineJobsLevel = this.Get_DetermineJobLevel + 1; db.Jobs.Add(j); db.SaveChanges(); MessageBox.Show("New job created successfully."); this.Close(); } else if (this.formType == 2) { if (txt_jobName.Text.Trim() == "") { MessageBox.Show("Enter the job title."); return; } var query_update = (from J in db.Jobs where J.jobsID == this.Get_jobId select J).SingleOrDefault(); query_update.jobsName = txt_jobName.Text.Trim(); query_update.jobsDetail = txt_jobDetail.Text.Trim(); db.SaveChanges(); MessageBox.Show("Job information successfully edited."); this.Close(); } } catch { MessageBox.Show("There are problems with the server, please try again."); return; } }
private void btn_sabt_Click(object sender, EventArgs e) { if (txt_oldPassword.Text.Trim() == "" || txt_newPassword.Text.Trim() == "" || txt_newPasswordAgain.Text.Trim() == "") { MessageBox.Show("Please enter the required values"); return; } try { ///Check that the previous password is correct /////////////hashing password SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider(); Byte[] B1; Byte[] B2; B1 = UTF8Encoding.UTF8.GetBytes(txt_oldPassword.Text.Trim()); B2 = SHA256.ComputeHash(B1); string HashedPassword = BitConverter.ToString(B2); var query_oldPass = (from U in database.Users where U.userID == PublicVariable.gUserId where U.Password == HashedPassword select U).ToList(); if (query_oldPass.Count == 0) { MessageBox.Show("The old password is incorrect."); return; } if (txt_newPassword.Text.Trim() == txt_newPasswordAgain.Text.Trim()) { /////////////hashing password SHA256CryptoServiceProvider SHA256_newPass = new SHA256CryptoServiceProvider(); Byte[] B1_newPass; Byte[] B2_newPass; B1_newPass = UTF8Encoding.UTF8.GetBytes(txt_newPassword.Text.Trim()); B2_newPass = SHA256.ComputeHash(B1_newPass); string HashedPassword_newPass = BitConverter.ToString(B2_newPass); var query_updatePassword = (from U in database.Users where U.userID == PublicVariable.gUserId select U).SingleOrDefault(); query_updatePassword.Password = HashedPassword_newPass; database.SaveChanges(); MessageBox.Show("Password changed successfully."); this.Close(); } else { MessageBox.Show("The new password is not the same as repeating it!!"); return; } } catch { MessageBox.Show("There was a problem communicating with the server."); } }
private void btn_exit_Click(object sender, EventArgs e) { if (WhatType == 1) /// Letter { database.SP_UpdateMessage(PublicVariable.gUserId); } else if (WhatType == 2)/// Reference { database.Sp_updateErjaMessage(PublicVariable.gUserId); } database.SaveChanges(); this.Close(); }
/// s.21 private void btn_deactiveUser_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Are you sure you want to deactivate " + dgv_showUsers.CurrentRow.Cells["col_name"].Value.ToString() + " " + dgv_showUsers.CurrentRow.Cells["col_family"].Value.ToString() + " 's account", "Disable user", MessageBoxButtons.YesNo) == DialogResult.Yes) { int GetUserId = Convert.ToInt32(dgv_showUsers.CurrentRow.Cells["col_userId"].Value); var query = (from U in database.Users where U.userID == GetUserId select U).SingleOrDefault(); query.Activity = 2; database.SaveChanges(); MessageBox.Show("User successfully disabled."); ShowUserInfo(createSearchString()); } else { return; } } catch { MessageBox.Show("There was a problem with the server. Please try again"); } }
private void btn_ok_Click(object sender, EventArgs e) { if (!checkNullable()) { return; } try { Document D = new Document(); D.UserID = PublicVariable.gUserId; D.Doc_subject = txt_subject.Text.Trim(); D.Doc_description = txt_description.Text.Trim(); D.Doc_date = lbl_date.Text; D.Doc_exporter = txt_saderkonandeh.Text.Trim(); D.Doc_DeliveryFullname = txt_tahvildahandeh.Text.Trim(); /// attachment if (lbl_attachmentFile.Text != "") { FileStream objFileStream = new FileStream(lbl_attachmentFile.Text, FileMode.Open, FileAccess.Read); int intLength = Convert.ToInt32(objFileStream.Length); byte[] objData; objData = new byte[intLength]; String[] strPath = lbl_attachmentFile.Text.Split(Convert.ToChar(@"\")); objFileStream.Read(objData, 0, intLength); objFileStream.Close(); D.FileData = objData; D.FileSize = intLength; D.FileName = strPath[strPath.Length - 1]; } database.Documents.Add(D); database.SaveChanges(); MessageBox.Show("The document was successfully registered."); txt_description.Text = ""; txt_saderkonandeh.Text = ""; txt_subject.Text = ""; txt_tahvildahandeh.Text = ""; lbl_attachmentFile.Text = ""; ShowAllDocuments(searchCondition()); } catch { MessageBox.Show("There is a problem with the server."); return; } }
private void mnu_bayegany_Click(object sender, EventArgs e) { var query_accsess = (from UA in database.UsereAccesses where UA.userID == PublicVariable.gUserId where UA.SystemPardID == 27 select UA).ToList(); if (query_accsess.Count == 0) { MessageBox.Show("You do not have access to this section"); } ///Archive letters int item = dgv_showAllRecievedLetters.SelectedCells.Count; if (item > 0) { try { if (MessageBox.Show("Are you sure you want to archive letter" + dgv_showAllRecievedLetters.CurrentRow.Cells["Letterno"].Value.ToString(), "Archive the letter", MessageBoxButtons.YesNo) == DialogResult.Yes) { int GetLetterID = Convert.ToInt32(dgv_showAllRecievedLetters.CurrentRow.Cells["LetterID"].Value); var query = (from L in database.Letters where L.LetterId == GetLetterID select L).SingleOrDefault(); query.BayganiType = 2; database.SaveChanges(); MessageBox.Show("The letter was successfully archived."); ShowAllRecievedLetter(searchCondition()); } } catch { MessageBox.Show("There was a problem with the server. Please try again."); } } else { MessageBox.Show("Please select a letter first."); return; } }
private void btn_giveJob_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you confident of dismissal?", "Dismissal", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { var query = (from P in database.Userjobs where P.userID == this.Get_UserID where P.Status == 1 select P).SingleOrDefault(); query.Status = 2; query.UserJobEndDate = PublicVariable.TodayDate; database.SaveChanges(); MessageBox.Show("Job was taken successfully"); ShowUserInfo(); } catch { MessageBox.Show("There is a problem with the server. Please try again."); } } }
private void btn_ok_Click(object sender, EventArgs e) { if (txt_subject.Text == "" || txt_matn.Text == "") { MessageBox.Show("Enter the subject and text of the news to create and send news."); txt_subject.Focus(); return; } try { news N = new news(); N.UserID = PublicVariable.gUserId; N.subject = txt_subject.Text.Trim(); N.matn = txt_matn.Text.Trim(); N.NewsDate = lbl_newsDate.Text.Trim(); //// attachment if (lbl_attachmentFile.Text != "") { FileStream objFileStream = new FileStream(lbl_attachmentFile.Text, FileMode.Open, FileAccess.Read); int intLength = Convert.ToInt32(objFileStream.Length); byte[] objData; objData = new byte[intLength]; String[] strPath = lbl_attachmentFile.Text.Split(Convert.ToChar(@"\")); objFileStream.Read(objData, 0, intLength); objFileStream.Close(); N.Attachment = objData; N.AttachmentFileSize = intLength; N.AttachmentFileName = strPath[strPath.Length - 1]; } database.news.Add(N); database.SaveChanges(); MessageBox.Show("Announcement sent successfully."); this.Close(); } catch { MessageBox.Show("There is something wrong with the server. Please try again."); return; } }
private void dgvShowRemembers_DoubleClick(object sender, EventArgs e) { if (dgvShowRemembers.SelectedCells.Count > 0) { MessageBox.Show(dgvShowRemembers.CurrentRow.Cells["matn"].Value.ToString(), dgvShowRemembers.CurrentRow.Cells["subject"].Value.ToString()); try { int getrememberID = Convert.ToInt32(dgvShowRemembers.CurrentRow.Cells["RememberId"].Value); //////Update by linq to entity //////select * from Remember where rememberID = getrememberID var updateQuery = (from R in database.Remembers where R.RememberID == getrememberID select R).SingleOrDefault(); updateQuery.IsRead = 2; database.SaveChanges(); ShowRemember(searchCondition()); } catch { MessageBox.Show("There was a problem communicating with the server. Try again."); } } }
private void btn_newLetter_Click(object sender, EventArgs e) { if (txt_subject.Text.Trim() == "" || txt_chekideh.Text.Trim() == "" || advancedTextEditor_matn.TextEditor.Text.Trim() == "") { MessageBox.Show("Please enter the full letter information"); return; } if (this.FormType == 1) { using (TransactionScope ts = new TransactionScope()) { try { Letter L = new Letter(); L.subject = txt_subject.Text.Trim(); L.abstrct = txt_chekideh.Text.Trim(); L.matn = advancedTextEditor_matn.TextEditor.Text; ///Make a letter number { /// Year + User job level + / + Last ID Letter +1 var Last_LetterID = (from Leter in database.Letters orderby Leter.LetterId descending select Leter).First(); L.letterNo = PublicVariable.TodayDate.Substring(2, 2) + PublicVariable.gDetermineJobsLevel + "/" + (Last_LetterID.LetterId + 1); } L.createDate = lbl_createDate.Text; L.userID = PublicVariable.gUserId; if (rdb_tabaghe_adi.Checked) { L.SecurityType = 1; } else if (rdb_tabaghe_mahramane.Checked) { L.SecurityType = 2; } else if (rdb_tabaghe_seri.Checked) { L.SecurityType = 3; } if (rdb_foriyat_adi.Checked) { L.ForceType = 1; } else if (rdb_foriyat_fori.Checked) { L.ForceType = 2; } else if (rdb_foriyat_ani.Checked) { L.ForceType = 3; } L.BayganiType = 1; if (rdb_peygiri_darad.Checked) { L.PeygiryType = 1; } else if (rdb_peygiri_nadarad.Checked) { L.PeygiryType = 2; } if (rdb_peyvast_darad.Checked) { L.AttachmentType = 1; } else if (rdb_peyvast_nadarad.Checked) { L.AttachmentType = 2; } // L.ReadType = 1; if (this.IsReply == 1)// reply { L.LetterType = 2; } else { L.LetterType = 1; } L.DraftType = 1; if (rdb_mohlat_darad.Checked) { L.answerType = 1; L.answerDeadline = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(persianDateTimePicker_mohlatPasokh.Value.Year + "/" + persianDateTimePicker_mohlatPasokh.Value.Month + "/" + persianDateTimePicker_mohlatPasokh.Value.Day)); } else if (rdb_mohlat_nadarad.Checked) { L.answerType = 2; L.Reffrence = this.Get_LetterNo; L.replyLetterId = this.Get_LetterID; } database.Letters.Add(L); database.SaveChanges(); ///////// Attach File if (rdb_peyvast_darad.Checked == true) { if (lbl_path.Text != "") { FileStream objFileStream = new FileStream(lbl_path.Text, FileMode.Open, FileAccess.Read); int intLength = Convert.ToInt32(objFileStream.Length); byte[] objData; objData = new byte[intLength]; String[] strPath = lbl_path.Text.Split(Convert.ToChar(@"\")); objFileStream.Read(objData, 0, intLength); objFileStream.Close(); AttachFile AF = new AttachFile(); AF.FileSize = intLength / 1024; ///KB AF.FileName = strPath[strPath.Length - 1]; AF.FileData = objData; AF.LetterID = L.LetterId; database.AttachFiles.Add(AF); database.SaveChanges(); } } ts.Complete(); if (this.IsReply == 1) { MessageBox.Show("The reply was successfully created and moved to the drafts section."); } else { MessageBox.Show("The letter was successfully created and moved to the drafts section."); } } catch { MessageBox.Show("There is a problem with the server. try again."); } } } else if (this.FormType == 2) //edit { using (TransactionScope ts = new TransactionScope()) { try { var query_update = (from L in database.Letters where L.LetterId == this.Get_LetterID where L.userID == PublicVariable.gUserId select L).SingleOrDefault(); query_update.subject = txt_subject.Text.Trim(); query_update.abstrct = txt_chekideh.Text.Trim(); query_update.matn = advancedTextEditor_matn.TextEditor.Text; query_update.createDate = lbl_createDate.Text; if (rdb_tabaghe_adi.Checked) { query_update.SecurityType = 1; } else if (rdb_tabaghe_mahramane.Checked) { query_update.SecurityType = 2; } else if (rdb_tabaghe_seri.Checked) { query_update.SecurityType = 3; } if (rdb_foriyat_adi.Checked) { query_update.ForceType = 1; } else if (rdb_foriyat_fori.Checked) { query_update.ForceType = 2; } else if (rdb_foriyat_ani.Checked) { query_update.ForceType = 3; } if (rdb_peygiri_darad.Checked) { query_update.PeygiryType = 1; } else if (rdb_peygiri_nadarad.Checked) { query_update.PeygiryType = 2; } if (rdb_peyvast_darad.Checked) { query_update.AttachmentType = 1; } else if (rdb_peyvast_nadarad.Checked) { ///پیوست ندارد query_update.AttachmentType = 2; } if (rdb_mohlat_darad.Checked) { query_update.answerType = 1; query_update.answerDeadline = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(persianDateTimePicker_mohlatPasokh.Value.Year + "/" + persianDateTimePicker_mohlatPasokh.Value.Month + "/" + persianDateTimePicker_mohlatPasokh.Value.Day)); } else if (rdb_mohlat_nadarad.Checked) { query_update.answerType = 2; query_update.answerDeadline = ""; } database.SaveChanges(); ///////// attach file if (rdb_peyvast_darad.Checked == true) { if (lbl_path.Text != "") { var query_checkAttachment = (from AF in database.AttachFiles where AF.LetterID == Get_LetterID select AF).ToList(); //The letter has not had attachment but now it has if (query_checkAttachment.Count == 0) { FileStream objfilestream = new FileStream(lbl_path.Text, FileMode.Open, FileAccess.Read); int intlength = Convert.ToInt32(objfilestream.Length); byte[] objdata; objdata = new byte[intlength]; string[] strpath = lbl_path.Text.Split(Convert.ToChar(@"\")); objfilestream.Read(objdata, 0, intlength); objfilestream.Close(); AttachFile af = new AttachFile(); af.FileSize = intlength / 1024; ///kb af.FileName = strpath[strpath.Length - 1]; af.FileData = objdata; af.LetterID = this.Get_LetterID; database.AttachFiles.Add(af); database.SaveChanges(); } else if (query_checkAttachment.Count == 1) // The letter has already had attachment and still has { if (lbl_path.Text != query_checkAttachment[0].FileName) ///The letter already has an attachment, but it is the same as the previous file { FileStream objfilestream = new FileStream(lbl_path.Text, FileMode.Open, FileAccess.Read); int intlength = Convert.ToInt32(objfilestream.Length); byte[] objdata; objdata = new byte[intlength]; string[] strpath = lbl_path.Text.Split(Convert.ToChar(@"\")); objfilestream.Read(objdata, 0, intlength); objfilestream.Close(); var query_updateAttach = (from AF in database.AttachFiles where AF.LetterID == this.Get_LetterID select AF).SingleOrDefault(); query_updateAttach.FileSize = intlength / 1024; ///kb query_updateAttach.FileName = strpath[strpath.Length - 1]; query_updateAttach.FileData = objdata; database.SaveChanges(); } } } } else if (rdb_peyvast_nadarad.Checked = true) ///If it already had it, but not now { try { var query_checkAttachment = (from AF in database.AttachFiles where AF.LetterID == this.Get_LetterID select AF).ToList(); if (query_checkAttachment.Count > 0) { var query_delete = (from AF in database.AttachFiles where AF.LetterID == this.Get_LetterID select AF).SingleOrDefault(); database.AttachFiles.Remove(query_delete); database.SaveChanges(); } } catch { MessageBox.Show("There is a problem with the server. try again"); return; } } ts.Complete(); MessageBox.Show("The letter was successfully edited and moved to the drafts section."); } catch { MessageBox.Show("There is a problem with the server. try again."); return; } } } }
private void lbl_exit_Click(object sender, EventArgs e) { database.SP_Update_ExitDate(PublicVariable.gUserId, PublicVariable.TodayDate + "-" + string.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second))); database.SaveChanges(); System.Environment.Exit(0); }
private void btn_sabt_Click(object sender, EventArgs e) { if (this.formtype == 1) ///add user { if (!CheckNotNull()) { return; } try { //// check not duplicate user var checkRepeateUsername_query = (from U in database.Users where U.Username == txt_username.Text.Trim() where U.Activity == 1 select U).ToList(); if (checkRepeateUsername_query.Count == 1) { MessageBox.Show("The username entered is already selected"); return; } /////////////hashing password SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider(); Byte[] B1; Byte[] B2; B1 = UTF8Encoding.UTF8.GetBytes(txt_password.Text.Trim()); B2 = SHA256.ComputeHash(B1); string HashedPassword = BitConverter.ToString(B2); //////////// Create Image Array FileStream fs_userImage = new FileStream(userImageName, FileMode.Open, FileAccess.Read); byte[] imageByteArray = new byte[fs_userImage.Length]; fs_userImage.Read(imageByteArray, 0, Convert.ToInt32(fs_userImage.Length)); fs_userImage.Close(); //////////// Create Signature Image FileStream fs_UserSignature = new FileStream(UserSignatureName, FileMode.Open, FileAccess.Read); byte[] imageByteArray_Signature = new byte[fs_UserSignature.Length]; fs_UserSignature.Read(imageByteArray_Signature, 0, Convert.ToInt32(fs_UserSignature.Length)); fs_UserSignature.Close(); ///// check Gender byte checkGender = 0; if (rdb_man.Checked) { checkGender = 1; } else { checkGender = 2; } /////// Get Birthday Date string Birthday = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(persianDate_birthDay.Value.Year + "/" + persianDate_birthDay.Value.Month + "/" + persianDate_birthDay.Value.Day)); database.Sp_insert_Users(txt_name.Text, txt_family.Text, txt_username.Text, HashedPassword, txt_personalCode.Text, txt_email.Text, checkGender, 1, txt_tel.Text, Birthday.Trim(), imageByteArray , lbl_date.Text, imageByteArray_Signature); database.SaveChanges(); MessageBox.Show("New user created successfully"); this.Close(); } catch { MessageBox.Show("Errors in recording information. Please try again."); } } else if (this.formtype == 2) //// update user (s.20) { if (!CheckNotNull_forUpdateUser()) { return; } try { byte[] imageByteArray = null; if (userImageName != null) { //////////// Create User Image Array FileStream fs_userImage = new FileStream(userImageName, FileMode.Open, FileAccess.Read); imageByteArray = new byte[fs_userImage.Length]; fs_userImage.Read(imageByteArray, 0, Convert.ToInt32(fs_userImage.Length)); fs_userImage.Close(); } ///// check Gender byte checkGender = 0; if (rdb_man.Checked) { checkGender = 1; } else { checkGender = 2; } /////// User Birthday Date string Birthday = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(persianDate_birthDay.Value.Year + "/" + persianDate_birthDay.Value.Month + "/" + persianDate_birthDay.Value.Day)); if (userImageName != "") { database.Sp_Update_Users(this.userID, txt_name.Text.Trim(), txt_family.Text.Trim(), txt_personalCode.Text.Trim(), txt_email.Text.Trim(), checkGender, txt_tel.Text.Trim(), Birthday, imageByteArray); } else if (userImageName == "") { database.Sp_Update_Users_noImage(this.userID, txt_name.Text.Trim(), txt_family.Text.Trim(), txt_personalCode.Text.Trim(), txt_email.Text.Trim(), checkGender, txt_tel.Text.Trim(), Birthday); } database.SaveChanges(); MessageBox.Show("User information successfully edited"); this.Close(); } catch { MessageBox.Show("There was a problem registering user information. Please try again"); return; } } }
private void btn_SendLetter_Click(object sender, EventArgs e) { using (TransactionScope ts = new TransactionScope()) { try { if (this.IsErja == 1)///if it was referal { List <DataGridView> row_with_check_column = new List <DataGridView>(); foreach (DataGridViewRow row in dgv_SelectUserToSend.Rows) { ReferenceLetter RL = new ReferenceLetter(); if (Convert.ToBoolean(row.Cells["selectUser"].Value) == true) { /// Letter control operation to prevent redirection. int GetUserID_reciever = Convert.ToInt32(row.Cells["UserID"].Value); var query_checkNotErja = (from RefL in database.ReferenceLetters where RefL.LetterId == this.GetLetterID where RefL.UserID_sender == PublicVariable.gUserId where RefL.UserID_Reciever == GetUserID_reciever select RefL).ToList(); if (query_checkNotErja.Count == 0) { /// Will be referred /// Referral operations var query = (from Re in database.ReferenceLetters where Re.LetterId == this.GetLetterID orderby Re.LevelNo descending select Re).ToList(); if (query.Count > 0) { var LastlevelNumber = query.First().LevelNo; RL.LevelNo = LastlevelNumber + 1; } else { RL.LevelNo = 1; } RL.LetterId = this.GetLetterID; RL.UserID_Reciever = Convert.ToInt32(row.Cells["UserID"].Value); RL.UserID_sender = PublicVariable.gUserId; RL.ReferenceDate = PublicVariable.TodayDate; RL.ReadType = 1; RL.Description = txt_descreptionErja.Text.Trim(); RL.IsMessage = 1; database.ReferenceLetters.Add(RL); } else { MessageBox.Show("This letter has already been referred to " + row.Cells["fullname"].Value.ToString()); return; } } } database.SaveChanges(); ts.Complete(); MessageBox.Show("The letter was successfully forwarded."); this.Close(); } else { /// Remove the letter from the draft var query_update = (from L in database.Letters where L.LetterId == this.GetLetterID select L).SingleOrDefault(); query_update.DraftType = 2; query_update.sentLetterDate = PublicVariable.TodayDate; database.SaveChanges(); /// sending letter List <DataGridView> row_with_check_column = new List <DataGridView>(); foreach (DataGridViewRow row in dgv_SelectUserToSend.Rows) { SentLetter SL = new SentLetter(); if (Convert.ToBoolean(row.Cells["selectUser"].Value) == true) { SL.LetterID = this.GetLetterID; SL.UserID = Convert.ToInt32(row.Cells["UserID"].Value); SL.ReadType = 1; SL.Ismessage = 1; database.SentLetters.Add(SL); } } database.SaveChanges(); ts.Complete(); MessageBox.Show("Letter sent successfully."); this.Close(); } } catch { MessageBox.Show("There are problems with the server. Please try again."); return; } } }
private void btn_enter_Click(object sender, EventArgs e) { automation_systemEntities database = new automation_systemEntities(PublicVariable.MainConnectionString); try { if (txt_username.Text.Trim() != "" && txt_password.Text.Trim() != "") { /////////////hashing password SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider(); Byte[] B1; Byte[] B2; B1 = UTF8Encoding.UTF8.GetBytes(txt_password.Text.Trim()); B2 = SHA256.ComputeHash(B1); string HashedPassword = BitConverter.ToString(B2); var login_query = (from U in database.Users where U.Username == txt_username.Text.Trim() where U.Password == HashedPassword where U.Activity == 1 select U).ToList(); if (login_query.Count == 1) { /// Obtain user profile for use throughout the app PublicVariable.gUserFirstName = login_query[0].UserFirstName; PublicVariable.gUserFamilyName = login_query[0].UserFamily; PublicVariable.gUserId = login_query[0].userID; /////Register user profile in log file to control entry and exit s.22 string computerName = System.Environment.MachineName; UserLog UL = new UserLog(); UL.ComputerName = computerName; UL.IpAddress = lbl_IP.Text.Trim(); UL.EnterDateTime = lbl_date.Text.Trim() + "-" + string.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second)); UL.UserId = PublicVariable.gUserId; database.UserLogs.Add(UL); database.SaveChanges(); } else { MessageBox.Show("The user was not found"); return; } if (rdb_admin.Checked) { if (txt_username.Text.Trim() == "admin") { PublicVariable.gSetUser = 1; ////admin } else { MessageBox.Show("The user does not have administrator access"); return; } } else { PublicVariable.gSetUser = 2; ///users } this.Close(); } } catch { MessageBox.Show("There is a problem with the server, please try again"); } }
private void btn_SendNote_Click(object sender, EventArgs e) { //Check that the subject and text are not empty if (txt_SubjectNote.Text == "" || txt_matnNote.Text == "") { MessageBox.Show("Please enter subject and text."); txt_SubjectNote.Focus(); return; } // کنترل انتخاب نکردن گیرنده int counter = 0; foreach (DataGridViewRow row in dgv_SelectUserToSend.Rows) { if (Convert.ToBoolean(row.Cells["selectUser"].Value) == true) { counter += 1; } } if (counter == 0) { MessageBox.Show("Please select a note recipient."); return; } using (TransactionScope ts = new TransactionScope()) { try { ///Create notes Note N = new Note(); N.subject = txt_SubjectNote.Text.Trim(); N.matn = txt_matnNote.Text.Trim(); N.NoteDate = lbl_dateNote.Text; N.userId = PublicVariable.gUserId; database.Notes.Add(N); database.SaveChanges(); ///Send notes List <DataGridView> row_with_check_column = new List <DataGridView>(); foreach (DataGridViewRow row in dgv_SelectUserToSend.Rows) { SentNote SN = new SentNote(); if (Convert.ToBoolean(row.Cells["selectUser"].Value) == true) { SN.NoteID = N.noteID; SN.UserID = Convert.ToInt32(row.Cells["UserID"].Value); database.SentNotes.Add(SN); } } database.SaveChanges(); ts.Complete(); MessageBox.Show("The note was sent successfully."); } catch { MessageBox.Show("There are problems with the server, please try again."); return; } } }