public void SendVerificationLinkEmail(string emailID, string activationCode, string emailFor = "VerifyAccount") { var verifyUrl = "/User/" + emailFor + "/" + activationCode; var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl); string body = string.Empty, subject = string.Empty; if (emailFor == "VerifyAccount") { subject = "Your account is successfully created! Verify Account"; body = "Dear " + SessionManager.UserName + ",<br/><br/>We are excited to tell you that your account is" + " successfully created. Please click on the below link to verify your account" + " <br/><br/><a href='" + link + "'>" + link + "</a> " + "<br/><br/> From:<br/> Admin, IRD-SRIC, IITR"; } else if (emailFor == "ResetPassword") { subject = "Reset Password"; body = "Dear " + SessionManager.UserName + ", <br/>br/>We got request for reset your account password. Please click on the below link to reset your password" + "<br/><br/><a href=" + link + ">Reset Password link</a>" + "<br/><br/> From:<br/> Admin, IRD-SRIC, IITR"; } FormServices formServices = new FormServices(); formServices.SendEmail(emailID, "", subject, body); }
private void toolCreateServiceToolStripMenuItem_Click(object sender, EventArgs e) { FormServices frmLunServ = new FormServices(); frmLunServ.MdiParent = this; frmLunServ.Show(); }
public async Task ReturnCorrectDtoWhen_ParamsAreValid() { //Arrange var options = Utils.GetOptions(nameof(ReturnCorrectDtoWhen_ParamsAreValid)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var testId = Guid.NewGuid(); var form = new Form { Id = testId, Title = "TestForm1", Description = "TestDescription" }; using (var arrangeContext = new SurvelloContext(options)) { await arrangeContext.Forms.AddAsync(form); await arrangeContext.SaveChangesAsync(); } //Act & Assert using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); var result = await sut.GetFormAsync(testId); Assert.AreEqual(form.Id, result.Id); Assert.AreEqual(form.Title, result.Title); Assert.AreEqual(form.Description, result.Description); } }
public async Task ThrowException_WhenNoUserFormsFound() { var options = Utils.GetOptions(nameof(ThrowException_WhenNoUserFormsFound)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var userId = Guid.NewGuid(); var user = new User { Id = userId, UserName = "******" }; using (var arrangeContext = new SurvelloContext(options)) { await arrangeContext.Users.AddAsync(user); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); await Assert.ThrowsExceptionAsync <BusinessLogicException>(() => sut.GetUserFormsAsync(userId)); } }
public static T GetSelectedRow <T>(string Text, string HeaderText, IEnumerable <T> DataSource, T SelectedRow, params SelectItemForm.ColumnDefinition[] Columns) { if (DataSource == null || DataSource.Count() == 0) { return(default(T)); } if (DataSource.Count() == 1) { return(DataSource.First()); } using (var form = new SelectItemForm(new SortableBindingList <T>(DataSource), SelectedRow == null ? DataSource.First() : SelectedRow, Columns)) { if (!string.IsNullOrWhiteSpace(Text)) { form.Text = Text; } if (!string.IsNullOrWhiteSpace(HeaderText)) { form.SetHeaderText(HeaderText); } if (FormServices.ShowFormDialog(form) == DialogResult.OK && form.bindingSource.Current is T) { return((T)form.bindingSource.Current); } else { return(default(T)); } } }
public static T GetSelectedRow <T>(DataTable DataSource, T SelectedRow, params SelectItemForm.ColumnDefinition[] Columns) where T : DataRow { if (DataSource == null || DataSource.Rows.Count == 0) { return(null); } if (DataSource.Rows.Count == 1) { return(DataSource.Rows[0] as T); } using (var form = new SelectItemForm(DataSource, SelectedRow ?? DataSource.Rows[0], Columns)) if (FormServices.ShowFormDialog(form) == DialogResult.OK) { var drv = form.bindingSource.Current as DataRowView; if (drv != null) { return(drv.Row as T); } else { return(form.bindingSource.Current as T); } } else { return(null); } }
public async Task ReturnTrue_WhenFormIsDeleted() { //Arrange var options = Utils.GetOptions(nameof(ReturnTrue_WhenFormIsDeleted)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var form = new Form { Id = Guid.NewGuid(), Title = "TestForm" }; using (var arrangeContext = new SurvelloContext(options)) { await arrangeContext.Forms.AddAsync(form); await arrangeContext.SaveChangesAsync(); } //Act & Assert using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); var result = await sut.DeleteFormAsync(form.Id); Assert.IsTrue(result); } }
//======================================================================// //======================================================================// //======================================================================// #endregion #region SERVICES FUNCTIONS //======================================================================// //======================= SERVICES ===================================// //======================================================================// private void btnAddService_Click(object sender, EventArgs e) { FormServices f = new FormServices(); f.ShowDialog(); UpdateServiceList("", false); }
public async Task ReturnCorrectFormDtoWhen_ParamsAreValid() { //Arrange var options = Utils.GetOptions(nameof(ReturnCorrectFormDtoWhen_ParamsAreValid)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var testId = Guid.NewGuid(); var testId2 = Guid.NewGuid(); var testId3 = Guid.NewGuid(); var form = new Form { Id = testId, Title = "TestForm1", Description = "TestDescription", UserId = testId3 }; var form2 = new Form { Id = testId2, Title = "TestForm2", Description = "TestDescription2", UserId = testId3 }; var user = new User { Id = testId3, UserName = "******" }; using (var arrangeContext = new SurvelloContext(options)) { await arrangeContext.Users.AddAsync(user); await arrangeContext.Forms.AddAsync(form); await arrangeContext.Forms.AddAsync(form2); await arrangeContext.SaveChangesAsync(); } //Act & Assert using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); var result = (await sut.GetUserFormsAsync(testId3)).ToList(); Assert.AreEqual(2, result.Count); Assert.AreEqual(form.Id, result[0].Id); Assert.AreEqual(form.Title, result[0].Title); Assert.AreEqual(form.Description, result[0].Description); Assert.AreEqual(form2.Id, result[1].Id); Assert.AreEqual(form2.Title, result[1].Title); Assert.AreEqual(form2.Description, result[1].Description); } }
public void SortByNumberOfFilledFormDesc() { //Arrange var options = Utils.GetOptions(nameof(SortByNumberOfFilledFormDesc)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var testId = Guid.NewGuid(); var testId2 = Guid.NewGuid(); var testId3 = Guid.NewGuid(); var sortOrder = "numberoffilledforms_desc"; var form1 = new Form { Id = testId, Title = "FirstPlace", UserId = testId3, CreatedOn = DateTime.Now, NumberOfFilledForms = 5 }; var form2 = new Form { Id = testId2, Title = "SecondPlace", UserId = testId3, CreatedOn = DateTime.UtcNow, NumberOfFilledForms = 3 }; var user = new User { Id = testId3, UserName = "******" }; using (var arrangeContext = new SurvelloContext(options)) { arrangeContext.Users.AddAsync(user); arrangeContext.Forms.AddAsync(form1); arrangeContext.Forms.AddAsync(form2); arrangeContext.Forms.AddAsync(form2); arrangeContext.SaveChangesAsync(); } //Act & Assert using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); var result = sut.Sort(sortOrder, user.Id).ToArray(); Assert.AreEqual(form1.Id, result.First().Id); Assert.AreEqual(form1.Title, result.First().Title); Assert.AreEqual(form1.NumberOfFilledForms, result.First().NumberOfFilledForms); Assert.AreEqual(form2.Id, result.Last().Id); Assert.AreEqual(form2.Title, result.Last().Title); Assert.AreEqual(form2.CreatedOn, result.Last().CreatedOn); } }
public async Task ThrowException_WhenDtoIsNull() { var options = Utils.GetOptions(nameof(ThrowException_WhenDtoIsNull)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var id = Guid.NewGuid(); using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); await Assert.ThrowsExceptionAsync <BusinessLogicException>(() => sut.CreateFormAsync(null)); } }
public async Task ThrowExcep_WhenNoFormFound() { var options = Utils.GetOptions(nameof(ThrowExcep_WhenNoFormFound)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var id = Guid.NewGuid(); using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); await Assert.ThrowsExceptionAsync <BusinessLogicException>(() => sut.GetFormWithAllAnswers(id)); } }
public void SortByTitleDesc_Succeed() { //Arrange var options = Utils.GetOptions(nameof(SortByTitleDesc_Succeed)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var testId = Guid.NewGuid(); var testId2 = Guid.NewGuid(); var testId3 = Guid.NewGuid(); var sortOrder = "title_desc"; var form1 = new Form { Id = testId, Title = "FirstPlace", UserId = testId3 }; var form2 = new Form { Id = testId2, Title = "SecondPlace", UserId = testId3 }; var user = new User { Id = testId3, UserName = "******" }; using (var arrangeContext = new SurvelloContext(options)) { arrangeContext.Users.AddAsync(user); arrangeContext.Forms.AddAsync(form1); arrangeContext.Forms.AddAsync(form2); arrangeContext.Forms.AddAsync(form2); arrangeContext.SaveChangesAsync(); } //Act & Assert using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); var result = sut.Sort(sortOrder, user.Id); Assert.AreEqual(form1.Id, result.Last().Id); Assert.AreEqual(form1.Title, result.Last().Title); Assert.AreEqual(form2.Id, result.First().Id); Assert.AreEqual(form2.Title, result.First().Title); } }
/// <summary> /// /// </summary> /// <param name="DataSource"></param> /// <param name="Text"></param> /// <param name="HeaderText"></param> /// <param name="Columns"></param> /// <returns></returns> public static void ShowData(object DataSource, string Text, string HeaderText, params SelectItemForm.ColumnDefinition[] Columns) { using (var form = new SelectItemForm(DataSource, null, Columns)) { if (!string.IsNullOrWhiteSpace(Text)) { form.Text = Text; } if (!string.IsNullOrWhiteSpace(HeaderText)) { form.SetHeaderText(HeaderText); } FormServices.ShowFormDialog(form); } }
public ActionResult SendEnquiry(ContactUsViewModels ContactUsViewModels) { string body = ("Message: " + ContactUsViewModels.Message + "<br/>From:- " + "<br/> Name:" + ContactUsViewModels.Name + "<br/> EmpNo:" + ContactUsViewModels.EmpNo + "<br/> Mobile No:" + ContactUsViewModels.MobileNo + "<br/> Email:" + ContactUsViewModels.Email + "<br/> <br /> Sent by: IRD-SRIC, IIT Roorkee"); FormServices formServices = new FormServices(); formServices.SendEmail("*****@*****.**", ContactUsViewModels.Email, ContactUsViewModels.Subject, body); ViewBag.Status = true; ViewBag.Message = "Email has been sent successfully. We will contact you soon."; ModelState.Clear(); return(View("Contact", new ContactUsViewModels())); }
public ResponseDTO ValidateFormNoBorn([FromBody] QualifiedLead model) { FormServices formAnswerService = new FormServices(); var response = new ResponseDTO(); try { var retQualified = formAnswerService.CheckQualifieNoBornQuestionForm(model); YouAre youAreObj = (YouAre)Enum.Parse(typeof(YouAre), model.Situation); if (retQualified) { if (youAreObj == YouAre.PregnantChildLessFiveYears) { formAnswerService.InsertQualifiedLeadtoBitrixQueue(model, retQualified, "PLUSS"); } else if (youAreObj == YouAre.PregnantFirstChild || youAreObj == YouAre.PregnantChildMoreFiveYears) { formAnswerService.InsertQualifiedLeadtoBitrixQueue(model, retQualified, "DPP"); } } else { formAnswerService.InsertDisQualifiedLeadtoBitrixQueue(model, retQualified, "NOQUALIFIED"); } var ret = formAnswerService.InsertLeadToGoogleDoc(model, retQualified); if (ret) { response.Data = new { sucesso = 1, message = "Formulario validado com sucesso!" }; } else { response.Data = new { sucesso = 0, message = "Não foi possível validar o formulário!" }; } } catch (Exception ex) { response.Message = ex.Message; } return(response); }
static void Main(string[] args) { Bitrix24Services objService = new Bitrix24Services(); AttendantServices attedantasService = new AttendantServices(); FormServices formService = new FormServices(); DepartmentServices departmentServices = new DepartmentServices(); List <Department> lstDepartments = departmentServices.GetDepartments(); //objService.CreateLead("Silvia Aparecida", 12, "Silvia Aparecida", "1198987787", "*****@*****.**","NEW"); //objService.CreateLead("Amanda Nunes", 12, "Amanda Nunes", "1198987787", "*****@*****.**", "1"); //objService.CreateLead("Renata dos Santos", 12, "Renata dos Santos", "1198987787", "*****@*****.**", "IN_PROCESS"); //objService.GetDepartments(); //List<Attendant> lstAttendants = attedantasService.GetAttendants(); //objService.GetEmployeeDepartments(); //List<string> lstString = formService.GetNextUserDepartmentLeadDisQualifield(); Console.WriteLine("Hello World!"); }
private void dgServices_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (dgServices.SelectedRows.Count != 0) { try { DBConnector db = new DBConnector(); Service es = db.SearchService("s.id", dgServices.SelectedRows[0].Cells[0].Value.ToString(), false)[0]; FormServices f = new FormServices(); f.EditingMode(es); f.ShowDialog(); //UpdateServiceList(); } catch (Exception ex) { MessageBox.Show(ex.Message); //throw; } } }
internal static DataRow GetSelectedRow(object DataSource, string ValueMember = null, string DisplayMember = null, object SelectedValue = null, bool AutoGenerateColumns = false) { SelectItemForm.ColumnDefinition[] Columns = null; if (!AutoGenerateColumns && !string.IsNullOrWhiteSpace(ValueMember) && !string.IsNullOrWhiteSpace(DisplayMember)) { Columns = new SelectItemForm.ColumnDefinition[] { SelectItemForm.CreateColumnDefinition("Value", ValueMember), SelectItemForm.CreateColumnDefinition("Name", DisplayMember, FillWeight: 100), }; } using (var form = new SelectItemForm(DataSource, SelectedValue, Columns)) { try { var pos = form.bindingSource.Find(ValueMember, SelectedValue); if (pos >= 0) { form.bindingSource.Position = pos; } } catch { } if (FormServices.ShowFormDialog(form) == DialogResult.OK) { var drv = form.bindingSource.Current as DataRowView; if (drv != null) { return(drv.Row); } else { return(form.bindingSource.Current as DataRow); } } else { return(null); } } }
public async Task ThrowWhen_FormNotFound() { var options = Utils.GetOptions(nameof(ThrowWhen_FormNotFound)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var testId = Guid.NewGuid(); var testId2 = Guid.NewGuid(); var form = new Form { Id = testId, Title = "TestForm1", Description = "TestDescription" }; using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); await Assert.ThrowsExceptionAsync <BusinessLogicException>(() => sut.GetFormAsync(testId2)); } }
/// <summary> /// Columns generator that works on column data descriptions (ColumnDataDescriptor) /// </summary> /// <param name="dataGrid">DataGridView</param> /// <param name="DataSource">Data Source to support data-binding</param> /// <param name="Columns">Column data descriptors</param> public static void GenerateColumns(this DataGridView dataGrid, object DataSource, params ColumnDataDescriptor[] Columns) { dataGrid.SuspendLayout(); dataGrid.AutoGenerateColumns = false; dataGrid.Columns.Clear(); foreach (var column in Columns) { if (column.Mode == ColumnEditorMode.TextBox) { var newColumn = new DataGridViewTextBoxColumn(); column.GeneratedDataGridViewColumn = newColumn; newColumn.SortMode = DataGridViewColumnSortMode.Automatic; newColumn.HeaderText = column.HeaderText; if (column.MaxLength.HasValue) { newColumn.MaxInputLength = column.MaxLength.Value; } if (newColumn.MaxInputLength > 260) { newColumn.DefaultCellStyle = new DataGridViewCellStyle() { WrapMode = DataGridViewTriState.True } } ; if (column.FillWeight.HasValue) { newColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; newColumn.FillWeight = column.FillWeight.Value; newColumn.MinimumWidth = column.HeaderText.Length * 10; if (newColumn.MinimumWidth < 50) { newColumn.MinimumWidth = 50; } } newColumn.ToolTipText = column.ColumnName; newColumn.DataPropertyName = column.ColumnName; if (column.NullValue != null) { if (newColumn.DefaultCellStyle != null) { newColumn.DefaultCellStyle.NullValue = column.NullValue; } else { newColumn.DefaultCellStyle = new DataGridViewCellStyle() { NullValue = column.NullValue } }; } newColumn.ReadOnly = column.IsReadOnly; if (column.Style.HasValue) { DataGridViewExtenders.SetEditorDataStyle(newColumn, column.Style.Value); } dataGrid.Columns.Add(newColumn); if (column.FormatValueMethod != null) { newColumn.Tag = column.FormatValueMethod; dataGrid.CellFormatting += delegate(object sender, DataGridViewCellFormattingEventArgs e) { var _data = newColumn.Tag as FormatValueDelegate; if (_data != null && e.ColumnIndex == newColumn.Index && e.RowIndex >= 0) { var _value = _data.Invoke(dataGrid.Rows[e.RowIndex].DataBoundItem, newColumn.DataPropertyName); if (_value != null) { e.Value = _value; e.FormattingApplied = _value is string; } } }; } } else if (column.Mode == ColumnEditorMode.CheckBox) { var newColumn = new DataGridViewCheckBoxColumn(); column.GeneratedDataGridViewColumn = newColumn; newColumn.SortMode = DataGridViewColumnSortMode.Automatic; newColumn.HeaderText = column.HeaderText; if (column.FillWeight.HasValue) { newColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; newColumn.FillWeight = column.FillWeight.Value; newColumn.MinimumWidth = column.HeaderText.Length * 10; if (newColumn.MinimumWidth < 50) { newColumn.MinimumWidth = 50; } } newColumn.ToolTipText = column.ColumnName; newColumn.ThreeState = column.IsNull; newColumn.DataPropertyName = column.ColumnName; newColumn.ReadOnly = column.IsReadOnly; dataGrid.Columns.Add(newColumn); } else if (column.Mode == ColumnEditorMode.ListBox) { DataGridViewColumn newColumn; if (column.IsReadOnly) { var _newColumn = new DataGridViewTextBoxColumn(); newColumn = _newColumn; } else { var _newColumn = new DataGridViewLinkColumn(); _newColumn.TrackVisitedState = false; _newColumn.LinkBehavior = LinkBehavior.HoverUnderline; newColumn = _newColumn; } column.GeneratedDataGridViewColumn = newColumn; newColumn.SortMode = DataGridViewColumnSortMode.Automatic; newColumn.HeaderText = column.HeaderText; if (column.FillWeight.HasValue) { newColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; newColumn.FillWeight = column.FillWeight.Value; newColumn.MinimumWidth = column.HeaderText.Length * 10; if (newColumn.MinimumWidth < 50) { newColumn.MinimumWidth = 50; } } newColumn.ToolTipText = column.ColumnName; newColumn.DataPropertyName = column.ColumnName; newColumn.ReadOnly = true; if (column.Style.HasValue) { DataGridViewExtenders.SetEditorDataStyle(newColumn, column.Style.Value); } newColumn.Tag = Tuple.Create(column.DataSource, column.ValueMember, column.DisplayMember, column.GetListBoxItemsMethod, column.FormatValueMethod); dataGrid.Columns.Add(newColumn); dataGrid.CellFormatting += delegate(object sender, DataGridViewCellFormattingEventArgs e) { var _data = newColumn.Tag as Tuple <object, string, string, GetListBoxItemsDelegate, FormatValueDelegate>; if (_data != null && e.ColumnIndex == newColumn.Index && e.RowIndex >= 0) { if (_data.Item5 != null) { var _value = _data.Item5.Invoke(dataGrid.Rows[e.RowIndex].DataBoundItem, newColumn.DataPropertyName); if (_value != null) { e.Value = _value; e.FormattingApplied = _value is string; } } else if (dataGrid.Rows[e.RowIndex].DataBoundItem is DataRowView && (_data.Item1 is DataView || _data.Item1 is DataTable)) { var dataBoundItem = (DataRowView)dataGrid.Rows[e.RowIndex].DataBoundItem; var _data1 = _data.Item1 is DataView ? ((DataView)_data.Item1).Table : (DataTable)_data.Item1; var _row = _data1.Rows.Find(dataBoundItem[newColumn.DataPropertyName]); e.Value = _row != null ? _row[_data.Item3].ToString() : string.Empty; e.FormattingApplied = true; } } }; if (!column.IsReadOnly) { dataGrid.CellClick += delegate(object sender, DataGridViewCellEventArgs e) { var _data = newColumn.Tag as Tuple <object, string, string, GetListBoxItemsDelegate, FormatValueDelegate>; if (_data != null && e.ColumnIndex == newColumn.Index && e.RowIndex >= 0 && dataGrid.Rows[e.RowIndex].DataBoundItem is DataRowView) { var dataBoundItem = (DataRowView)dataGrid.Rows[e.RowIndex].DataBoundItem; object items = _data.Item1; bool agc = false; if (_data.Item4 != null) { items = _data.Item4.Invoke(); if (items == null) { FormServices.ShowError("No data exists", true); return; } agc = true; } var row = SelectItemForm.GetSelectedRow(items, _data.Item2, _data.Item3, dataBoundItem[newColumn.DataPropertyName], agc); if (row != null) { dataBoundItem.BeginEdit(); dataBoundItem[newColumn.DataPropertyName] = row[_data.Item2]; dataBoundItem.EndEdit(); } } } } ; } else if (column.Mode == ColumnEditorMode.ComboBox) { var newColumn = new DataGridViewComboBoxColumn(); column.GeneratedDataGridViewColumn = newColumn; newColumn.DisplayStyleForCurrentCellOnly = true; newColumn.DisplayStyle = column.IsReadOnly ? DataGridViewComboBoxDisplayStyle.Nothing : DataGridViewComboBoxDisplayStyle.DropDownButton; newColumn.AutoComplete = true; if (column.IsNull) { newColumn.DefaultCellStyle = new DataGridViewCellStyle() { DataSourceNullValue = DBNull.Value } } ; newColumn.SortMode = DataGridViewColumnSortMode.Automatic; newColumn.HeaderText = column.HeaderText; if (column.FillWeight.HasValue) { newColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; newColumn.FillWeight = column.FillWeight.Value; newColumn.MinimumWidth = column.HeaderText.Length * 10; if (newColumn.MinimumWidth < 50) { newColumn.MinimumWidth = 50; } } newColumn.ToolTipText = column.ColumnName; newColumn.DataPropertyName = column.ColumnName; newColumn.DataSource = column.DataSource; if (!string.IsNullOrWhiteSpace(column.ValueMember)) { newColumn.ValueMember = column.ValueMember; } if (!string.IsNullOrWhiteSpace(column.DisplayMember)) { newColumn.DisplayMember = column.DisplayMember; } newColumn.ReadOnly = column.IsReadOnly; dataGrid.Columns.Add(newColumn); if (column.FormatValueMethod != null) { newColumn.Tag = column.FormatValueMethod; dataGrid.CellFormatting += delegate(object sender, DataGridViewCellFormattingEventArgs e) { var _data = newColumn.Tag as FormatValueDelegate; if (_data != null && e.ColumnIndex == newColumn.Index && e.RowIndex >= 0) { var _value = _data.Invoke(dataGrid.Rows[e.RowIndex].DataBoundItem, newColumn.DataPropertyName); if (_value != null) { e.Value = _value; e.FormattingApplied = _value is string; } } }; } } } dataGrid.DataSource = DataSource; dataGrid.ResumeLayout(false); }
public ActionResult UpdateUserDetail(RankUserViewModel rankUserViewModel, string[] MenuList) { bool Status = false; DataCollectionModelDataContext db = new DataCollectionModelDataContext(); RankUser rankUser = db.RankUsers.Where(a => a.UserID == rankUserViewModel.RankUser.UserID).FirstOrDefault(); if (rankUser != null) { rankUser.DeptID = rankUserViewModel.RankUser.DeptID; rankUser.UserDisabledOn = Convert.ToString(rankUserViewModel.RankUser.UserValid) == "N" ? DateTime.Now : (DateTime?)null; rankUser.UserEmail = rankUserViewModel.RankUser.UserEmail; rankUser.UserEmpNo = rankUserViewModel.RankUser.UserEmpNo; rankUser.UserMob = rankUserViewModel.RankUser.UserMob; rankUser.UserName = rankUserViewModel.RankUser.UserName; rankUser.UserRole = rankUserViewModel.RankUser.UserRole; rankUser.UserValid = Convert.ToChar(rankUserViewModel.RankUser.UserValid ?? null); rankUser.UserWork = rankUserViewModel.RankUser.UserWork; db.Connection.Open(); using (db.Transaction = db.Connection.BeginTransaction()) { try { IEnumerable <UserMenu> userMenu = db.UserMenus.Where(a => a.UserID == rankUserViewModel.RankUser.UserID).ToList(); if (userMenu != null) { var sa = userMenu.Where(a => !MenuList.Contains(a.MenuID)).ToList(); if (sa.Any()) { db.UserMenus.DeleteAllOnSubmit(sa); } } List <UserMenu> userMenuList = new List <UserMenu>(); foreach (string item in MenuList) { var sa = userMenu.Where(a => a.MenuID == item).FirstOrDefault(); if (sa == null) { UserMenu menu = new UserMenu(); menu.MenuID = item; menu.UserID = rankUserViewModel.RankUser.UserID; userMenuList.Add(menu); } } if (userMenuList.Any()) { db.UserMenus.InsertAllOnSubmit(userMenuList); } db.SubmitChanges(); db.Transaction.Commit(); Status = true; ViewBag.Message = "User Updated Successfully."; ViewBag.Status = true; try { if (rankUserViewModel.RankUser.UserValid == "Y") { string body = "Dear " + rankUserViewModel.RankUser.UserName + ",<br /> You have been authorised by admin now. You can access the system by logging in. <br /><br /> Admin <br /> IRD SRIC"; FormServices formServices = new FormServices(); body = body.Replace("\r\n", "<br />"); string subject = "User Authorised by Admin, IRD-SRIC, IITR"; formServices.SendEmail(rankUserViewModel.RankUser.UserEmail, "", subject, body); } } catch (Exception ex) { } } catch (Exception ex) { db.Transaction.Rollback(); ViewBag.Message = "Failed To Updated User. Error: " + ex.Message; ViewBag.Status = false; } } } return(Json(new { success = Status })); }
private void buttonOpenServiсes_Click(object sender, EventArgs e) { Form formServices = new FormServices(); formServices.Show(); }
public async Task CorrectlyGetAllAnswers() { //Arrange var options = Utils.GetOptions(nameof(CorrectlyGetAllAnswers)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var userId = Guid.NewGuid(); var formId = Guid.NewGuid(); var multipleChoicOptionId = Guid.NewGuid(); var form = new Form { Id = formId, Title = "TestForm", Description = "TestDescrtiption", UserId = userId, TextQuestions = new List <TextQuestion>() { new TextQuestion { Description = "Where are you from?", IsLongAnswer = false, IsRequired = true, Answers = new List <TextAnswer>() { new TextAnswer() { Answer = "Bourgas", } } } }, MultipleChoiceQuestions = new List <MultipleChoiceQuestion>() { new MultipleChoiceQuestion { Description = "How would you rate your experience with our product?", IsRequired = true, IsMultipleAnswer = false, Options = new List <MultipleChoiceOption>() { new MultipleChoiceOption { Option = "Satisfied", //Answers = new List<MultipleChoiceAnswer>() //{ // new MultipleChoiceAnswer() // { // MultipleChoiceOptionId = multipleChoicOptionId // } //} } } } }, DocumentQuestions = new List <DocumentQuestion>() { new DocumentQuestion { Description = "TestDescription", FileNumberLimit = 10, FileSize = 1, Answers = new List <DocumentAnswer>() { new DocumentAnswer() { FileName = "TestFilePath" } } } } }; var user = new User { Id = userId, UserName = "******" }; using (var arrangeContext = new SurvelloContext(options)) { await arrangeContext.Forms.AddAsync(form); await arrangeContext.SaveChangesAsync(); } //Act & Assert using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); //await sut.GetFormWithAllAnswers(formId); var result = assertContext.Forms.First(); var resultTA = assertContext.TextAnswers.First(); var resultMCA = assertContext.MultipleChoiceAnswers.First(); var resultDA = assertContext.DocumentAnswers.First(); var resultOptions = assertContext.MultipleChoiceOptions.First(); Assert.AreEqual(form.Title, result.Title); Assert.AreEqual(form.Description, result.Description); foreach (var tq in form.TextQuestions) { foreach (var ta in tq.Answers) { Assert.AreEqual(ta.Answer, resultTA.Answer); } } foreach (var mcq in form.MultipleChoiceQuestions) { foreach (var op in mcq.Options) { //foreach (var mcqa in op.Answers) //{ // Assert.AreEqual(mcqa.MultipleChoiceOptionId,resultMCA.MultipleChoiceOptionId); //} } } foreach (var dq in form.DocumentQuestions) { foreach (var da in dq.Answers) { Assert.AreEqual(da.FileName, resultDA.FileName); } } } }
private void button4_Click(object sender, EventArgs e) { FormServices.ShowAllDiseases(dataGridView1); }
private void button5_Click(object sender, EventArgs e) { FormServices.ShowAllAddresses(dataGridView1); }
public async Task CorrectlyCreatedForm() { //Arrange var options = Utils.GetOptions(nameof(CorrectlyCreatedForm)); var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockBlobService = new Mock <IBlobServices>(); var userId = Guid.NewGuid(); var formDto = new FormDTO { Title = "TestForm", Description = "TestDescrtiption", UserId = userId, TextQuestions = new List <TextQuestionDTO>() { new TextQuestionDTO { Description = "Where are you from?", IsLongAnswer = false, IsRequired = true, } }, MultipleChoiceQuestions = new List <MultipleChoiceQuestionDTO>() { new MultipleChoiceQuestionDTO { Description = "How would you rate your experience with our product?", IsRequired = true, IsMultipleAnswer = false, Options = new List <MultipleChoiceOptionDTO>() { new MultipleChoiceOptionDTO { OptionDescription = "Satisfied", } } } }, DocumentQuestions = new List <DocumentQuestionDTO>() { new DocumentQuestionDTO { Description = "TestDescription", FileNumberLimit = 10, FileSize = 1, } } }; var user = new User { Id = userId, UserName = "******" }; //Act & Assert using (var assertContext = new SurvelloContext(options)) { var sut = new FormServices(assertContext, mockDateTimeProvider.Object, mockBlobService.Object); await sut.CreateFormAsync(formDto); var result = assertContext.Forms.First(); var resultTQ = assertContext.TextQuestions.First(); var resultMCQ = assertContext.MultipleChoiceQuestions.First(); var resultDQ = assertContext.DocumentQuestions.First(); var resultOptions = assertContext.MultipleChoiceOptions.First(); Assert.AreEqual(formDto.Title, result.Title); Assert.AreEqual(formDto.Description, result.Description); foreach (var tq in formDto.TextQuestions) { Assert.AreEqual(tq.Description, resultTQ.Description); Assert.AreEqual(tq.IsLongAnswer, resultTQ.IsLongAnswer); Assert.AreEqual(tq.IsRequired, resultTQ.IsRequired); } foreach (var mcq in formDto.MultipleChoiceQuestions) { Assert.AreEqual(mcq.Description, resultMCQ.Description); Assert.AreEqual(mcq.IsMultipleAnswer, resultMCQ.IsMultipleAnswer); Assert.AreEqual(mcq.IsRequired, resultMCQ.IsRequired); foreach (var op in mcq.Options) { Assert.AreEqual(op.OptionDescription, resultOptions.Option); } } foreach (var dq in formDto.DocumentQuestions) { Assert.AreEqual(dq.Description, resultDQ.Description); Assert.AreEqual(dq.FileNumberLimit, resultDQ.FileNumberLimit); Assert.AreEqual(dq.FileSize, resultDQ.FileSize); } } }
private static void dataGrid_DataError(object sender, DataGridViewDataErrorEventArgs e) { FormServices.ShowError(e.Exception); e.ThrowException = false; e.Cancel = true; }
/// <summary> /// Fields generator that works on field data descriptions (FieldDataDescriptor) /// </summary> /// <param name="dataPanel">TableLayoutPanel</param> /// <param name="toolTip">ToolTip</param> /// <param name="DataSource">Data Source to support data-binding</param> /// <param name="Fields">Field data descriptors</param> public static void GenerateFields(this TableLayoutPanel dataPanel, ToolTip toolTip, object DataSource, params FieldDataDescriptor[] Fields) { dataPanel.SuspendLayout(); dataPanel.Controls.Clear(); if (DataSource == null || Fields == null || Fields.Length == 0) { return; } dataPanel.ColumnStyles.Clear(); dataPanel.ColumnCount = 2; dataPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); dataPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); dataPanel.RowStyles.Clear(); dataPanel.RowCount = 0; dataPanel.AutoSize = true; dataPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; dataPanel.Margin = new Padding(3, 3, 9, 3); int tabIndex = 0; foreach (var field in Fields) { dataPanel.RowCount += 1; dataPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize)); #region creating the label var leadLabel = new Label(); leadLabel.Text = field.CaptionText; // TODO: add option for generating label in format: column.CaptionText + ":" leadLabel.TextAlign = ContentAlignment.MiddleRight; leadLabel.Padding = new Padding(0, 0, 0, 0); if (field.Mode == FieldEditorMode.MultilineTextBox || field.Mode == FieldEditorMode.BitMask || field.Mode == FieldEditorMode.BitMask64) { leadLabel.Anchor = AnchorStyles.Right | AnchorStyles.Top; leadLabel.Margin = new Padding(12, 6, 0, 6); } else { leadLabel.Anchor = AnchorStyles.Right; leadLabel.Margin = new Padding(12, 1, 0, 1); } leadLabel.TabIndex = tabIndex++; leadLabel.AutoSize = true; dataPanel.Controls.Add(leadLabel, 0, dataPanel.RowCount - 1); #endregion Binding binding = null; if (field.Mode == FieldEditorMode.TextBox || field.Mode == FieldEditorMode.MultilineTextBox || field.Mode == FieldEditorMode.DateTimeTextBox) { #region creating editor control for text var _textBox = new TextBox(); field.GeneratedControl = _textBox; _textBox.Multiline = field.Mode == FieldEditorMode.MultilineTextBox; _textBox.Size = new Size(field.SizeWidth.HasValue ? field.SizeWidth.Value : (int)DataDescriptorSizeWidth.Normal, _textBox.Multiline ? 125 : 20); _textBox.Anchor = AnchorStyles.Left; if (field.MaxLength.HasValue) { _textBox.MaxLength = field.MaxLength.Value; } _textBox.TabIndex = tabIndex++; if (toolTip != null) { toolTip.SetToolTip(_textBox, field.ColumnName); } leadLabel.Click += delegate { _textBox.Focus(); }; binding = new Binding("Text", DataSource, field.ColumnName, true, field.IsReadOnly ? DataSourceUpdateMode.Never : DataSourceUpdateMode.OnPropertyChanged); if (field.FormatValueMethod != null) { _textBox.Tag = field.FormatValueMethod; binding.FormattingEnabled = true; binding.Format += TableLayoutPanelExtenders.BindingFormat; } if (field.IsNull) { binding.DataSourceNullValue = DBNull.Value; } if (field.NullValue != null) { binding.NullValue = field.NullValue; } if (field.Style.HasValue) { TableLayoutPanelExtenders.SetBindingStyle(binding, field.Style.Value); _textBox.TextAlign = field.Style == EditorDataStyle.DateTime || field.Style == EditorDataStyle.Date ? HorizontalAlignment.Center : HorizontalAlignment.Right; } _textBox.DataBindings.Add(binding); _textBox.ReadOnly = field.IsReadOnly; if (field.DataSource != null && field.DataSource is string[]) { _textBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend; _textBox.AutoCompleteSource = AutoCompleteSource.CustomSource; _textBox.AutoCompleteCustomSource = new AutoCompleteStringCollection(); _textBox.AutoCompleteCustomSource.AddRange((string[])field.DataSource); } dataPanel.Controls.Add(_textBox, 1, dataPanel.RowCount - 1); #endregion } else if (field.Mode == FieldEditorMode.NumberTextBox) { #region creating editor control for numbers var _textBox = new NumericUpDown(); field.GeneratedControl = _textBox; _textBox.Minimum = field.Minimum.HasValue ? field.Minimum.Value : decimal.MinValue; _textBox.Maximum = field.Maximum.HasValue ? field.Maximum.Value : decimal.MaxValue; _textBox.DecimalPlaces = 0; _textBox.ThousandsSeparator = true; _textBox.Size = new Size(field.SizeWidth.HasValue ? field.SizeWidth.Value : (int)DataDescriptorSizeWidth.Normal, 20); _textBox.Anchor = AnchorStyles.Left; _textBox.TabIndex = tabIndex++; if (toolTip != null) { toolTip.SetToolTip(_textBox, field.ColumnName); } leadLabel.Click += delegate { _textBox.Focus(); }; binding = new Binding("Text", DataSource, field.ColumnName, true, field.IsReadOnly ? DataSourceUpdateMode.Never : DataSourceUpdateMode.OnPropertyChanged); if (field.FormatValueMethod != null) { _textBox.Tag = field.FormatValueMethod; binding.FormattingEnabled = true; binding.Format += TableLayoutPanelExtenders.BindingFormat; } if (field.IsNull) { binding.DataSourceNullValue = DBNull.Value; } if (field.NullValue != null) { binding.NullValue = field.NullValue; } if (field.Style.HasValue) { TableLayoutPanelExtenders.SetBindingStyle(binding, field.Style.Value); _textBox.TextAlign = HorizontalAlignment.Right; } _textBox.DataBindings.Add(binding); _textBox.ReadOnly = field.IsReadOnly; dataPanel.Controls.Add(_textBox, 1, dataPanel.RowCount - 1); #endregion } else if (field.Mode == FieldEditorMode.CheckBox) { #region creating editor control for booleans var _checkBox = new CheckBox(); field.GeneratedControl = _checkBox; _checkBox.Anchor = AnchorStyles.Left; _checkBox.AutoSize = false; _checkBox.Size = new Size(20, 20); _checkBox.TabIndex = tabIndex++; if (toolTip != null) { toolTip.SetToolTip(_checkBox, field.ColumnName); } leadLabel.Click += delegate { _checkBox.Checked = !_checkBox.Checked; }; if (field.IsNull) { _checkBox.DataBindings.Add(new Binding("CheckState", DataSource, field.ColumnName, true, field.IsReadOnly ? DataSourceUpdateMode.Never : DataSourceUpdateMode.OnPropertyChanged, CheckState.Indeterminate)); _checkBox.ThreeState = true; } else { _checkBox.DataBindings.Add(new Binding("Checked", DataSource, field.ColumnName, false, field.IsReadOnly ? DataSourceUpdateMode.Never : DataSourceUpdateMode.OnPropertyChanged, false)); } _checkBox.Enabled = !field.IsReadOnly; dataPanel.Controls.Add(_checkBox, 1, dataPanel.RowCount - 1); #endregion } else if (field.Mode == FieldEditorMode.ListBox) { #region creating editor control for lists with dialog var _comboBox = new ComboBox(); field.GeneratedControl = _comboBox; _comboBox.Size = new Size(field.SizeWidth.HasValue ? field.SizeWidth.Value : (int)DataDescriptorSizeWidth.Normal, 21); _comboBox.Anchor = AnchorStyles.Left; if (field.MaxLength.HasValue) { _comboBox.MaxLength = field.MaxLength.Value; } _comboBox.TabIndex = tabIndex++; _comboBox.DropDownStyle = ComboBoxStyle.Simple; if (toolTip != null) { toolTip.SetToolTip(_comboBox, field.ColumnName); } leadLabel.Click += delegate { _comboBox.Focus(); }; if (field.FormatValueMethod != null) { binding = new Binding("Text", DataSource, field.ColumnName, true, DataSourceUpdateMode.Never); _comboBox.Tag = field.FormatValueMethod; binding.FormattingEnabled = true; binding.Format += TableLayoutPanelExtenders.BindingFormat; if (field.IsNull) { binding.DataSourceNullValue = DBNull.Value; } _comboBox.DataBindings.Add(binding); } else { binding = new Binding("SelectedValue", DataSource, field.ColumnName, true, DataSourceUpdateMode.Never); if (field.IsNull) { binding.DataSourceNullValue = DBNull.Value; } _comboBox.DataBindings.Add(binding); } _comboBox.DataSource = field.DataSource; if (!string.IsNullOrWhiteSpace(field.ValueMember)) { _comboBox.ValueMember = field.ValueMember; } if (!string.IsNullOrWhiteSpace(field.DisplayMember)) { _comboBox.DisplayMember = field.DisplayMember; } _comboBox.Enabled = false; if (field.IsReadOnly) { dataPanel.Controls.Add(_comboBox, 1, dataPanel.RowCount - 1); } else { var _pnl = new TableLayoutPanel(); _pnl.AutoSize = true; _pnl.AutoSizeMode = AutoSizeMode.GrowAndShrink; _pnl.Margin = new Padding(0); _pnl.Padding = new Padding(0); _pnl.RowCount = 1; _pnl.ColumnCount = 2; _pnl.RowStyles.Add(new RowStyle(SizeType.AutoSize)); _pnl.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); _pnl.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); _pnl.Controls.Add(_comboBox, 0, 0); var _btnSelect = new Button(); _btnSelect.Anchor = AnchorStyles.Left; _btnSelect.MaximumSize = new Size(128, 128); _btnSelect.Margin = new Padding(1, 0, 1, 0); _btnSelect.Padding = new Padding(0); _btnSelect.AutoSize = true; _btnSelect.AutoSizeMode = AutoSizeMode.GrowAndShrink; _btnSelect.FlatStyle = FlatStyle.Flat; _btnSelect.FlatAppearance.BorderSize = 0; _btnSelect.FlatAppearance.MouseOverBackColor = SystemColors.GradientActiveCaption; _btnSelect.FlatAppearance.MouseDownBackColor = SystemColors.ControlLight; _btnSelect.Image = Settings.Images.SelectRowImage; _btnSelect.ImageAlign = ContentAlignment.MiddleCenter; _btnSelect.TextAlign = ContentAlignment.MiddleCenter; _btnSelect.TabIndex = tabIndex++; _btnSelect.TabStop = false; if (toolTip != null) { toolTip.SetToolTip(_btnSelect, string.Format("Select a value for {0}", field.ColumnName)); } _pnl.Controls.Add(_btnSelect, 1, 0); _comboBox.Size = new Size((field.SizeWidth.HasValue ? field.SizeWidth.Value : (int)DataDescriptorSizeWidth.Normal) - _btnSelect.Width - _btnSelect.Margin.Left - _btnSelect.Margin.Right - _comboBox.Margin.Right, _comboBox.Height); _btnSelect.Click += delegate(object sender, EventArgs e) { var cm = binding.BindingManagerBase; if (cm != null) { try { var col = cm.GetItemProperties().Find(field.ColumnName, false); if (col != null) { object items = field.DataSource; bool agc = false; if (field.GetListBoxItemsMethod != null) { items = field.GetListBoxItemsMethod.Invoke(); if (items == null) { FormServices.ShowError("No data exists", true); return; } agc = true; } var row = SelectItemForm.GetSelectedRow(items, field.ValueMember, field.DisplayMember, col.GetValue(cm.Current), agc); if (row != null) { col.SetValue(cm.Current, row[field.ValueMember]); cm.EndCurrentEdit(); } } } catch (Exception ex) { FormServices.ShowError(ex); cm.CancelCurrentEdit(); } } }; dataPanel.Controls.Add(_pnl, 1, dataPanel.RowCount - 1); } #endregion } else if (field.Mode == FieldEditorMode.ComboBox || field.Mode == FieldEditorMode.ComboTextBox) { #region creating editor control for drop down lists var _comboBox = new ComboBox(); field.GeneratedControl = _comboBox; _comboBox.Size = new Size(field.SizeWidth.HasValue ? field.SizeWidth.Value : (int)DataDescriptorSizeWidth.Normal, 20); _comboBox.Anchor = AnchorStyles.Left; if (field.MaxLength.HasValue) { _comboBox.MaxLength = field.MaxLength.Value; } _comboBox.TabIndex = tabIndex++; _comboBox.DropDownStyle = field.Mode == FieldEditorMode.ComboBox ? ComboBoxStyle.DropDownList : ComboBoxStyle.DropDown; if (toolTip != null) { toolTip.SetToolTip(_comboBox, field.ColumnName); } leadLabel.Click += delegate { _comboBox.Focus(); if (_comboBox.Enabled) { _comboBox.DroppedDown = true; } }; binding = new Binding(field.Mode == FieldEditorMode.ComboBox ? "SelectedValue" : "Text", DataSource, field.ColumnName, true, field.IsReadOnly ? DataSourceUpdateMode.Never : DataSourceUpdateMode.OnPropertyChanged); if (field.IsNull) { binding.DataSourceNullValue = DBNull.Value; } _comboBox.DataBindings.Add(binding); _comboBox.DataSource = field.DataSource; if (!string.IsNullOrWhiteSpace(field.ValueMember)) { _comboBox.ValueMember = field.ValueMember; } if (!string.IsNullOrWhiteSpace(field.DisplayMember)) { _comboBox.DisplayMember = field.DisplayMember; } _comboBox.Enabled = !field.IsReadOnly; if (field.Mode == FieldEditorMode.ComboTextBox) { _comboBox.AutoCompleteMode = AutoCompleteMode.Append; _comboBox.AutoCompleteSource = AutoCompleteSource.ListItems; } dataPanel.Controls.Add(_comboBox, 1, dataPanel.RowCount - 1); #endregion } else if (field.Mode == FieldEditorMode.GuidEditor) { #region creating editor control for Guid var _textBox = new TextBox(); field.GeneratedControl = _textBox; _textBox.Size = new Size((int)DataDescriptorSizeWidth.Normal, 20); _textBox.Anchor = AnchorStyles.Left; _textBox.TabIndex = tabIndex++; if (toolTip != null) { toolTip.SetToolTip(_textBox, field.ColumnName); } leadLabel.Click += delegate { _textBox.Focus(); }; if (DataSource != null) { _textBox.DataBindings.Add(new Binding("Text", DataSource, field.ColumnName, true, DataSourceUpdateMode.Never, "(null)")); } _textBox.ReadOnly = true; dataPanel.Controls.Add(_textBox, 1, dataPanel.RowCount - 1); #endregion } else if (field.Mode == FieldEditorMode.BitMask || field.Mode == FieldEditorMode.BitMask64) { #region creating editor control for mask (bits) var _listBox = new BitMaskCheckedListBox(); field.GeneratedControl = _listBox; _listBox.Size = new Size(field.SizeWidth.HasValue ? field.SizeWidth.Value : (int)DataDescriptorSizeWidth.Normal, 150); _listBox.Anchor = AnchorStyles.Left; _listBox.TabIndex = tabIndex++; if (toolTip != null) { toolTip.SetToolTip(_listBox, field.ColumnName); } leadLabel.Click += delegate { _listBox.Focus(); }; binding = new Binding(field.Mode == FieldEditorMode.BitMask ? "Value" : "LongValue", DataSource, field.ColumnName, true, field.IsReadOnly ? DataSourceUpdateMode.Never : DataSourceUpdateMode.OnPropertyChanged); if (field.IsNull) { binding.DataSourceNullValue = DBNull.Value; } if (field.NullValue != null) { binding.NullValue = field.NullValue; } if (field.Style.HasValue) { TableLayoutPanelExtenders.SetBindingStyle(binding, field.Style.Value); } _listBox.DataBindings.Add(binding); _listBox.Enabled = !field.IsReadOnly; if (field.DataSource != null) { if (field.DataSource is string[]) { _listBox.Items.AddRange((string[])field.DataSource); if (_listBox.Items.Count > 0) { var _nHeight = _listBox.Items.Count * (_listBox.GetItemHeight(0) + 4) + 1; if (_nHeight < _listBox.Size.Height) { _listBox.Size = new Size(_listBox.Size.Width, _nHeight); } } } else { _listBox.DataSource = field.DataSource; _listBox.DisplayMember = field.DisplayMember; } } dataPanel.Controls.Add(_listBox, 1, dataPanel.RowCount - 1); #endregion } if (field.IsNull && !field.IsReadOnly && field.Mode != FieldEditorMode.CheckBox || field.Mode == FieldEditorMode.GuidEditor) { #region button for clear value if (dataPanel.ColumnCount == 2) { dataPanel.ColumnCount = 3; dataPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); } var _btnClear = new Button(); _btnClear.Anchor = AnchorStyles.Left; if (field.Mode == FieldEditorMode.MultilineTextBox) { _btnClear.Anchor |= AnchorStyles.Top; } _btnClear.MaximumSize = new Size(128, 128); _btnClear.Margin = new Padding(1, 0, 1, 0); _btnClear.Padding = new Padding(0); _btnClear.AutoSize = true; _btnClear.AutoSizeMode = AutoSizeMode.GrowAndShrink; _btnClear.FlatStyle = FlatStyle.Flat; _btnClear.FlatAppearance.BorderSize = 0; _btnClear.FlatAppearance.MouseOverBackColor = SystemColors.GradientActiveCaption; _btnClear.FlatAppearance.MouseDownBackColor = SystemColors.ControlLight; _btnClear.Image = Settings.Images.ClearFieldImage; _btnClear.ImageAlign = ContentAlignment.MiddleCenter; _btnClear.TextAlign = ContentAlignment.MiddleCenter; _btnClear.TabIndex = tabIndex++; _btnClear.TabStop = false; if (toolTip != null) { toolTip.SetToolTip(_btnClear, string.Format("Clear value from {0}", field.ColumnName)); } _btnClear.Click += delegate { var cm = binding.BindingManagerBase; if (cm != null) { try { var col = cm.GetItemProperties().Find(binding.BindingMemberInfo.BindingMember, false); if (col != null && cm.Count > 0) { col.SetValue(cm.Current, DBNull.Value); } cm.EndCurrentEdit(); binding.Control.Focus(); } catch (Exception ex) { FormServices.ShowError(ex); cm.CancelCurrentEdit(); } } }; dataPanel.Controls.Add(_btnClear, 2, dataPanel.RowCount - 1); #endregion } } dataPanel.ResumeLayout(false); }
public bool SaveUpdateFormData(object objectData, string action, string menu) { FormsViewModel formsViewModel = new FormsViewModel(); if (menu == DataAccess.Enum.Menu.DOSW.ToString() || menu == DataAccess.Enum.Menu.ADIR.ToString()) { stInfo2 info2 = new stInfo2(); info2 = JsonConvert.DeserializeObject <stInfo2>(objectData.ToString()); info2.DataUpdatedOn = DateTime.Now; info2.DataStatus = (int)DataAccess.Enum.DataStatus.DataEntryStartedbyOperator; if (action == "Finalize") { info2.DataStatus = (int)DataAccess.Enum.DataStatus.DataEntryCompletedbyOperator; } else if (action == "FinalizedByHod") { info2.DataStatus = (int)DataAccess.Enum.DataStatus.DataCheckingCompletedbyHOD; } info2.DataUser = SessionManager.UserName; info2.DeptID = SessionManager.DeptID; info2.DataValid = "Y"; info2.DataLocked = "N"; info2.DataStatusLog = SessionManager.UserName + " " + DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss"); //DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss tt"); if (menu == DataAccess.Enum.Menu.ADIR.ToString()) { info2.MenuID = DataAccess.Enum.Menu.ADIR.ToString(); } else { info2.MenuID = DataAccess.Enum.Menu.DOSW.ToString(); } formsViewModel.info2 = info2; if (formsViewModel.info2.IDNo > 0) { formsViewModel.isSaveSuccessfully = formsViewModel.UdpateADIRAndDOSWForm(formsViewModel); } else { formsViewModel.isSaveSuccessfully = formsViewModel.SaveADIRAndDOSWForm(formsViewModel); } } else if (menu == DataAccess.Enum.Menu.DOAA.ToString()) { stInfo info = new stInfo(); info = JsonConvert.DeserializeObject <stInfo>(objectData.ToString()); info.DataUpdatedOn = DateTime.Now; info.DataStatus = (int)DataAccess.Enum.DataStatus.DataEntryStartedbyOperator; if (action == "Finalize") { info.DataStatus = (int)DataAccess.Enum.DataStatus.DataEntryCompletedbyOperator; } else if (action == "FinalizedByHod") { info.DataStatus = (int)DataAccess.Enum.DataStatus.DataCheckingCompletedbyHOD; } info.DataUser = SessionManager.UserName; info.DeptID = SessionManager.DeptID; info.DataValid = "Y"; info.DataLocked = "N"; info.DataStatusLog = SessionManager.UserName + " " + DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss"); info.MenuID = DataAccess.Enum.Menu.DOAA.ToString(); formsViewModel.info = info; if (formsViewModel.info.IDNo > 0) { formsViewModel.isSaveSuccessfully = formsViewModel.UdpateDOAA1Form(formsViewModel); } else { formsViewModel.isSaveSuccessfully = formsViewModel.SaveDOAA1Form(formsViewModel); } } else if (menu == DataAccess.Enum.Menu.LIBFORM.ToString()) { LibInfo libInfo = new LibInfo(); libInfo = JsonConvert.DeserializeObject <LibInfo>(objectData.ToString()); libInfo.DataUpdatedOn = DateTime.Now; libInfo.DataStatus = (int)DataAccess.Enum.DataStatus.DataEntryStartedbyOperator; if (action == "Finalize") { libInfo.DataStatus = (int)DataAccess.Enum.DataStatus.DataEntryCompletedbyOperator; } else if (action == "FinalizedByHod") { libInfo.DataStatus = (int)DataAccess.Enum.DataStatus.DataCheckingCompletedbyHOD; } libInfo.DataUser = SessionManager.UserName; libInfo.DeptID = SessionManager.DeptID; libInfo.DataValid = "Y"; libInfo.DataLocked = "N"; libInfo.DataStatusLog = SessionManager.UserName + " " + DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss"); libInfo.MenuID = DataAccess.Enum.Menu.LIBFORM.ToString(); formsViewModel.libInfo = libInfo; if (formsViewModel.libInfo.IDNo > 0) { formsViewModel.isSaveSuccessfully = formsViewModel.UdpateLIBForm(formsViewModel); } else { formsViewModel.isSaveSuccessfully = formsViewModel.SaveLIBForm(formsViewModel); } } if (formsViewModel.isSaveSuccessfully && action == "Finalize") { try { string body = "The User: "******", Dept: " + SessionManager.DeptID + " , DataCapt: " + info.DataCaptYM + ", IRD Data has been finalised & sent for your Authorization. Kindly Check & Authorize/Approve the data." + "Time Stamp: DateTime Stamp: " + DateTime.Now + "This is a System generated Email."; string subject = "IRD Data Entry updated by " + SessionManager.UserName; DataCollectionModelDataContext db = new DataCollectionModelDataContext(); var hod = db.RankUsers.Where(a => a.DeptID.ToLower() == SessionManager.DeptID.ToLower() && a.UserRole.ToLower() == UserRoles.User.ToString().ToLower() && a.UserWork.ToLower() == DataAccess.Enum.UserWork.HOD.ToString().ToLower()).FirstOrDefault(); string tomail = "*****@*****.**"; if (hod != null) { tomail = hod.UserEmail; } FormServices formServices = new FormServices(); formServices.SendEmail(tomail, "", subject, body); } catch (Exception ex) { } } return(formsViewModel.isSaveSuccessfully); }