private void btnSave_Click(object sender, EventArgs e) { //User Table if (txtUserName.Text == "") { tbcUser.SelectedIndex = 0; Message.MsgInformation("Enter User Name"); txtUserName.Focus(); return; } if (txtPwd.Text == "") { tbcUser.SelectedIndex = 0; Message.MsgInformation("Enter Password"); txtPwd.Focus(); return; } if (cmbType.Text == "") { tbcUser.SelectedIndex = 0; Message.MsgInformation("Enter Level"); cmbType.Focus(); return; } User objUser = null; objUser = new User(); if ((_mode == "Add") || (_mode=="AddClone") || (_mode == "")) { objUser.Name = txtUserName.Text.Trim(); if (objUser.UserExists()) { Message.MsgInformation("Duplicate User Name not allowed"); tbcUser.SelectedIndex = 0; txtUserName.Focus(); return; } } else { if (txtUserName.Tag.ToString() != txtUserName.Text.Trim()) { objUser.Name = txtUserName.Text.Trim(); if (objUser.UserExists()) { Message.MsgInformation("Duplicate User Name not allowed"); tbcUser.SelectedIndex = 0; txtUserName.Focus(); return; } } } //Contacts Table if (txtFName.Text == "") { tbcUser.SelectedIndex = 1; Message.MsgInformation("Enter First Name"); txtFName.Focus(); return; } if (txtLName.Text == "") { tbcUser.SelectedIndex = 1; Message.MsgInformation("Enter Last Name"); txtLName.Focus(); return; } bool boolSuccess; Contact objContact = null; objContact = new Contact(); objContact.ContactID = 0; objContact.ContactType = 0; //for User objContact.LastName = txtLName.Text; objContact.LastNamePhonetic = txtLNamePhonetic.Text; objContact.LastNameRomaji = txtLNameRomaji.Text; objContact.FirstName = txtFName.Text; objContact.FirstNamePhonetic = txtFNamePhonetic.Text; objContact.FirstNameRomaji = txtFNameRomaji.Text; objContact.CompanyName = txtCompName.Text; objContact.CompanyNamePhonetic = txtCompPhonetic.Text; objContact.CompanyNameRomaji = txtCompRomaji.Text; objContact.TitleForName = cmbTitle.Text; objContact.TitleForJob = txtTitleJob.Text; objContact.Street1 = txtStreet1.Text; objContact.Street2 = txtStreet2.Text; objContact.Street3 = txtStreet3.Text; objContact.City = txtCity.Text; objContact.State = txtState.Text; objContact.PostalCode = txtPost.Text; objContact.Country = txtCountry.Text; //objContact.ContactType=cmbType.SelectedIndex; objContact.BlockCode = cmbBlock.Text; objContact.Email1 = txtEmail1.Text; objContact.Email2 = txtEmail2.Text; objContact.Phone1 = txtPhone1.Text; objContact.Phone2 = txtPhone2.Text; objContact.PhoneMobile1 = txtMobile1.Text; objContact.PhoneMobile2 = txtMobile2.Text; objContact.PhoneBusiness1 = txtPhone3.Text; objContact.PhoneBusiness2 = txtPhone4.Text; objContact.PhoneFax1 = txtFax1.Text; objContact.PhoneFax2 = txtFax2.Text; objContact.PhoneOther = txtPhoneOther.Text; objContact.Url = txtUrl.Text; objContact.TimeStatus = cmbEmpStatus.Text; if (dtDOB.Checked) objContact.DateBirth = dtDOB.Value; else objContact.DateBirth = Convert.ToDateTime(null); if (dtJoined.Checked) objContact.DateJoined = dtJoined.Value; else objContact.DateJoined = Convert.ToDateTime(null); if (dtEnded.Checked) objContact.DateEnded = dtEnded.Value; else objContact.DateEnded = Convert.ToDateTime(null); //objContact.TimeStatus=.Text; objContact.Nationality = txtNationality.Text; objContact.Married = cmbMarried.SelectedIndex; objContact.NumberDependents = Convert.ToInt16(txtNoDependent.Text); objContact.VisaStatus = txtVisaStatus.Text; if (dtVisaTo.Checked) objContact.VisaFromDate = dtVisaFrom.Value; else objContact.VisaFromDate = Convert.ToDateTime(null); if (dtVisaTo.Checked) objContact.VisaUntilDate = dtVisaTo.Value; else objContact.VisaUntilDate = Convert.ToDateTime(null); objContact.ClosestStation1 = txtClosestSt1.Text; objContact.ClosestLine1 = txtClosestLine1.Text; objContact.MinutesToStation1 = Convert.ToInt16(txtMintSt1.Text); objContact.ClosestStation2 = txtClosestSt2.Text; objContact.ClosestLine2 = txtClosestLine2.Text; objContact.MinutesToStation2 = Convert.ToInt16(txtMintSt2.Text); objContact.ContactStatus = cmbStatus.SelectedIndex; objContact.AccountRepLastName = ""; objContact.AccountRepLastNamePhonetic = ""; objContact.AccountRepLastNameRomaji = ""; objContact.AccountRepFirstName = ""; objContact.AccountRepFirstNamePhonetic = ""; objContact.AccountRepFirstNameRomaji = ""; objContact.ContactID = _contactid; /*if(objContact.Exists(txtFName.Text, txtLName.Text, 0)) { Scheduler.BusinessLayer.Message.MsgInformation("Duplicate Contact Name not allowed"); txtLName.Focus(); return; }*/ if ((_mode == "Add") || (_mode=="AddClone") || (_mode == "")) boolSuccess = objContact.InsertData(); else { objContact.ContactID = _contactid; boolSuccess = objContact.UpdateData(); } if (!boolSuccess) { if (_mode == "Add") Message.ShowException("Adding Contact record.", objContact.Message); else if (_mode=="AddClone") Message.ShowException("Cloning Contact record.", objContact.Message); else Message.ShowException("Updating Contact record.", objContact.Message); return; } //get the ContactID to insert it into User Table _contactid = objContact.ContactID; //User objUser.UserID = 0; objUser.ContactID = _contactid; objUser.Name = txtUserName.Text.Trim(); objUser.Pwd = txtPwd.Text.Trim(); //pass the encrypted password objUser.Pwd = SimpleHash.Encrypt(txtPwd.Text); objUser.TypeID = cmbType.SelectedIndex; objUser.StatusID = cmbStatus.SelectedIndex; if ((_mode == "Add") || (_mode == "AddClone") || (_mode == "")) { if (objUser.Exists()) { Message.MsgInformation("Duplicate User Name not allowed"); txtUserName.Focus(); return; } boolSuccess = objUser.InsertData(); } else { objUser.UserID = _userid; objUser.PasswordChanged = false; if (txtPwd.Text != txtPwd.Tag.ToString()) objUser.PasswordChanged = true; boolSuccess = objUser.UpdateData(); } if (!boolSuccess) { if (_mode == "Add" || _mode == "AddClone") Message.ShowException("Error occured while inserting user record.", objUser.Message); else Message.ShowException("Error occured while updating user record.", objUser.Message); return; } DialogResult = DialogResult.OK; Close(); }
private void btnLogin_Click(object sender, System.EventArgs e) { if((txtUser.Text.ToUpper()=="ADMIN") && (txtPwd.Text.ToUpper()=="SUPPORT")) { Common.LogonID=0; Common.LogonType=1; Common.LogonDate=DateTime.Now; this.DialogResult = DialogResult.OK; return; } intTry++; User objUser=new User(); objUser.Name=txtUser.Text; objUser.Pwd = txtPwd.Text; //pass the encrypted password //objUser.Pwd = MD5Hashing.Encrypt(txtPwd.Text); if(objUser.Exists()) { Common.LogonID = objUser.UserID; Common.LogonUser = txtUser.Text.Trim(); Common.LogonDate = DateTime.Now; Common.LogonType = objUser.TypeID; if(objUser.StatusID==1) { Scheduler.BusinessLayer.Message.MsgInformation("User is Inactive, cannot open..."); txtUser.Focus(); } else { this.DialogResult = DialogResult.OK; } } else { if(intTry<3) { Scheduler.BusinessLayer.Message.MsgInformation("Invalid User or Password"); txtUser.Focus(); } else { Scheduler.BusinessLayer.Message.MsgInformation("Exiting Application"); this.DialogResult = DialogResult.Cancel; } } }