1102 lines
39 KiB
C#
1102 lines
39 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Data;
|
|
using System.Globalization;
|
|
using System.Windows.Forms;
|
|
using Data.BusinessService;
|
|
using Data.DataModel;
|
|
using ClassLibrary;
|
|
using Projects;
|
|
|
|
namespace ControlLibrary
|
|
{
|
|
public partial class ProjectControl : UserControl
|
|
{
|
|
#region FIELDS
|
|
|
|
private IProjectService projectService;
|
|
private Project _project;
|
|
private int _projectId;
|
|
private decimal _resolutionX;
|
|
private decimal _resolutionY;
|
|
private float _frameWidth;
|
|
private float _frameHeight;
|
|
|
|
|
|
/// <summary>
|
|
/// Variable to store error message
|
|
/// </summary>
|
|
private string _errorMessage;
|
|
private bool _editMode;
|
|
|
|
#endregion
|
|
|
|
// Delegate declaration
|
|
public delegate void OnLoadDefault(ProjectControl sender, EventArgs e);
|
|
public event OnLoadDefault OnLoadedDefault;
|
|
public delegate void OkClicked(ProjectControl sender, EventArgs e);
|
|
public event OkClicked OnOkClicked;
|
|
public delegate void DeleteClicked(ProjectControl sender, EventArgs e);
|
|
public event DeleteClicked OnDeleteClicked;
|
|
public delegate void SaveAsDefaultClicked(ProjectControl sender, EventArgs e);
|
|
public event SaveAsDefaultClicked OnSaveAsDefaultClicked;
|
|
public delegate void PreviewClicked(ProjectControl sender, EventArgs e);
|
|
public event PreviewClicked OnPreviewClicked;
|
|
|
|
public ProjectControl()
|
|
{
|
|
InitializeComponent();
|
|
this.projectService = new ProjectService();
|
|
}
|
|
|
|
#region properties
|
|
|
|
// Control opened for Edit Project or Create Project
|
|
public bool EditMode
|
|
{
|
|
get { return _editMode; }
|
|
set { _editMode = value; }
|
|
}
|
|
|
|
public Project Project
|
|
{
|
|
get { return _project; }
|
|
set { _project = value; }
|
|
}
|
|
|
|
public string Caption
|
|
{
|
|
set { lblProject.Text = value; }
|
|
}
|
|
|
|
public string ProjectName
|
|
{
|
|
get { return txtProjectName.Text; }
|
|
set { txtProjectName.Text = value; }
|
|
}
|
|
|
|
public string OutPath
|
|
{
|
|
get { return txtOutPath.Text; }
|
|
set { txtOutPath.Text = value; }
|
|
}
|
|
|
|
public string HologramWidth
|
|
{
|
|
get { return txtHologW.Text; }
|
|
set { txtHologW.Text = value; }
|
|
}
|
|
|
|
public string HologramHeight
|
|
{
|
|
get { return txtHologH.Text; }
|
|
set { txtHologH.Text = value; }
|
|
}
|
|
|
|
public decimal ResolutionX
|
|
{
|
|
get { return _resolutionX; }
|
|
set { _resolutionX = value; }
|
|
}
|
|
|
|
public decimal ResolutionY
|
|
{
|
|
get { return _resolutionY; }
|
|
set { _resolutionY = value; }
|
|
}
|
|
|
|
public float FrameWidth
|
|
{
|
|
get { return _frameWidth; }
|
|
set { _frameWidth = value; }
|
|
}
|
|
|
|
public float FrameHeight
|
|
{
|
|
get { return _frameHeight; }
|
|
set { _frameHeight = value; }
|
|
}
|
|
|
|
public decimal GrayHigh
|
|
{
|
|
get { return numUpDownGrayHigh.Value; }
|
|
set { numUpDownGrayHigh.Value = value; }
|
|
}
|
|
|
|
public decimal GrayLow
|
|
{
|
|
get { return numUpDownGrayLow.Value; }
|
|
set { numUpDownGrayLow.Value = value; }
|
|
}
|
|
|
|
public int ProjectId
|
|
{
|
|
get { return _projectId; }
|
|
set { _projectId = value; }
|
|
}
|
|
|
|
public string Resolution
|
|
{
|
|
get { return cmbResolution.Text; }
|
|
set { cmbResolution.Text = value; }
|
|
}
|
|
|
|
public TrekoControl trekoControl
|
|
{
|
|
get
|
|
{
|
|
Control[] cnt = this.ParentForm.Controls.Find("TrekoControl", true);
|
|
return (TrekoControl)cnt[0];
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region helpers
|
|
|
|
/// <summary>
|
|
/// Method to show general error message on any system level exception
|
|
/// </summary>
|
|
private void ShowErrorMessage(Exception ex)
|
|
{
|
|
MessageBox.Show(
|
|
ex.Message,
|
|
//Resources.System_Error_Message,
|
|
Resources.System_Error_Message_Title,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Validates registration input
|
|
/// </summary>
|
|
/// <returns>true or false</returns>
|
|
private bool ValidateRegistration()
|
|
{
|
|
System.ComponentModel.CancelEventArgs e = null;
|
|
|
|
if (txtProjectName.Text.Trim() == string.Empty)
|
|
{
|
|
txtProjectName_Validating(this, e);
|
|
return false;
|
|
}
|
|
|
|
if (txtOutPath.Text.Trim() == string.Empty)
|
|
{
|
|
txtOutPath_Validating(this, e);
|
|
return false;
|
|
}
|
|
|
|
return true; // this.errorMessage != string.Empty ? false : true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validates update data
|
|
/// </summary>
|
|
/// <returns>true or false</returns>
|
|
private bool ValidateUpdate()
|
|
{
|
|
this._errorMessage = string.Empty;
|
|
|
|
//if (txt2Name.Text.Trim() == string.Empty)
|
|
//{
|
|
// this.AddErrorMessage(Resources.Registration_Name_Required_Text);
|
|
//}
|
|
|
|
//if (cmb2Occupation.SelectedIndex == -1)
|
|
//{
|
|
// this.AddErrorMessage(Resources.Registration_Occupation_Select_Text);
|
|
//}
|
|
|
|
//if (cmb2MaritalStatus.SelectedIndex == -1)
|
|
//{
|
|
// this.AddErrorMessage(Resources.Registration_MaritalStatus_Select_Text);
|
|
//}
|
|
|
|
//if (cmb2HealthStatus.SelectedIndex == -1)
|
|
//{
|
|
// this.AddErrorMessage(Resources.Registration_HealthStatus_Select_Text);
|
|
//}
|
|
|
|
return this._errorMessage != string.Empty ? false : true;
|
|
}
|
|
|
|
public void LoadProjectByNameDefault()
|
|
{
|
|
string projectName = Resources.Default_Project_Name;
|
|
|
|
DataRow dataRow = this.projectService.GetProjectByName(projectName);
|
|
|
|
// Assign the values to the model
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
//Id = Convert.ToInt16(dataRow["Id"]),
|
|
//ProjectName = dataRow["ProjectName"].ToString(),
|
|
OutPath = dataRow["OutPath"].ToString(),
|
|
//Author = this.textBoxAuthor.Text.Trim(),
|
|
CreatedDate = Convert.ToDateTime(dataRow["Created"]),
|
|
LastUpdatedDate = Convert.ToDateTime(dataRow["LastUpdated"]),
|
|
HologramWidth = Convert.ToDouble(dataRow["HologramWidth"]),
|
|
HologramHeight = Convert.ToDouble(dataRow["HologramHeight"]),
|
|
FrameWidth = Convert.ToDouble(dataRow["FrameWidth"]),
|
|
FrameHeight = Convert.ToDouble(dataRow["FrameHeight"]),
|
|
FrameResolutionX = Convert.ToInt16(dataRow["FrameResolutionX"]),
|
|
FrameResolutionY = Convert.ToInt16(dataRow["FrameResolutionY"]),
|
|
GrayRangeLow = Convert.ToInt16(dataRow["GrayRangeLow"]),
|
|
GrayRangeHigh = Convert.ToInt16(dataRow["GrayRangeHigh"]),
|
|
};
|
|
|
|
//DataTable data = this.projectService.GetProjectLayers(projectModel.Id);
|
|
//DataRow[] rows = data.Select(); // ("ParentID=" + 0);
|
|
|
|
_project = new Project(projectModel);
|
|
_project.ProjectId = 0;
|
|
_project.ProjectName = "";
|
|
_project.CreatedDate = DateTime.Now;
|
|
_project.LastUpdatedDate = DateTime.Now;
|
|
|
|
this.txtProjectName.Text = ""; // dataRow["ProjectName"].ToString();
|
|
this.txtOutPath.Text = dataRow["OutPath"].ToString();
|
|
this.txtHologW.Text = dataRow["HologramWidth"].ToString();
|
|
this.txtHologH.Text = dataRow["HologramHeight"].ToString();
|
|
this.FrameWidth = Convert.ToSingle(dataRow["FrameWidth"]);
|
|
this.FrameHeight = Convert.ToSingle(dataRow["FrameHeight"]);
|
|
this.ResolutionX = Convert.ToDecimal(dataRow["FrameResolutionX"]);
|
|
this.ResolutionY = Convert.ToDecimal(dataRow["FrameResolutionY"]);
|
|
this.numUpDownGrayLow.Value = (int)dataRow["GrayRangeLow"];
|
|
this.numUpDownGrayHigh.Value = (int)dataRow["GrayRangeHigh"];
|
|
|
|
SetCmbResolution();
|
|
|
|
OnLoadedDefault?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
private bool UpdateProjectDefault()
|
|
{
|
|
var success = false;
|
|
string projectName = Resources.Default_Project_Name;
|
|
|
|
try
|
|
{
|
|
if (this.ValidateUpdate())
|
|
{
|
|
cmbResolution_SelectedIndexChanged(this, EventArgs.Empty);
|
|
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = _project.ProjectId,
|
|
ProjectName = projectName, // txtProjectName.Text.Trim(),
|
|
OutPath = txtOutPath.Text.Trim(),
|
|
HologramWidth = double.Parse(txtHologW.Text),
|
|
HologramHeight = double.Parse(txtHologH.Text),
|
|
GrayRangeHigh = Convert.ToInt32(numUpDownGrayHigh.Value),
|
|
GrayRangeLow = Convert.ToInt32(numUpDownGrayLow.Value),
|
|
LastUpdatedDate = DateTime.Now,
|
|
FrameWidth = this.FrameWidth,
|
|
FrameHeight = this.FrameHeight,
|
|
FrameResolutionX = (int)this.ResolutionX,
|
|
FrameResolutionY = (int)this.ResolutionY,
|
|
|
|
};
|
|
|
|
var flag = this.projectService.UpdateProjectDefault(projectModel);
|
|
|
|
if (flag)
|
|
{
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
//this.LoadDataGridView(data);
|
|
|
|
//MessageBox.Show(
|
|
// Resources.Update_Successful_Message,
|
|
// Resources.Update_Successful_Message_Title,
|
|
// MessageBoxButtons.OK,
|
|
// MessageBoxIcon.Information);
|
|
success = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(
|
|
this._errorMessage,
|
|
Resources.Registration_Error_Message_Title,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
public bool UpdateProjectOutPath(string outPath)
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
var flag = this.projectService.UpdateProjectOutPath(_project.ProjectId, outPath);
|
|
|
|
if (flag)
|
|
{
|
|
this.OutPath = outPath;
|
|
this.Project.OutPath = outPath;
|
|
success = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
private bool UpdateProject()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
if (this.ValidateUpdate())
|
|
{
|
|
cmbResolution_SelectedIndexChanged(this, EventArgs.Empty);
|
|
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = _project.ProjectId,
|
|
ProjectName = txtProjectName.Text.Trim(),
|
|
OutPath = txtOutPath.Text.Trim(),
|
|
HologramWidth = double.Parse(txtHologW.Text),
|
|
HologramHeight = double.Parse(txtHologH.Text),
|
|
FrameWidth = this.FrameWidth,
|
|
FrameHeight = this.FrameHeight,
|
|
FrameResolutionX = (int)this.ResolutionX,
|
|
FrameResolutionY = (int)this.ResolutionY,
|
|
GrayRangeHigh = Convert.ToInt32(numUpDownGrayHigh.Value),
|
|
GrayRangeLow = Convert.ToInt32(numUpDownGrayLow.Value),
|
|
LastUpdatedDate = DateTime.Now,
|
|
};
|
|
|
|
var flag = this.projectService.UpdateProject(projectModel);
|
|
|
|
if (flag)
|
|
{
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
//this.LoadDataGridView(data);
|
|
|
|
//MessageBox.Show(
|
|
// Resources.Update_Successful_Message,
|
|
// Resources.Update_Successful_Message_Title,
|
|
// MessageBoxButtons.OK,
|
|
// MessageBoxIcon.Information);
|
|
success = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(
|
|
this._errorMessage,
|
|
Resources.Registration_Error_Message_Title,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
private bool deleteProjectColorProfiles()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
if (this.ValidateUpdate())
|
|
{
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = this.Project.ProjectId,
|
|
ProjectName = txtProjectName.Text.Trim(),
|
|
};
|
|
|
|
var flag = this.projectService.DeleteProjectColorProfiles(this.Project.ProjectId);
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(
|
|
this._errorMessage,
|
|
Resources.Registration_Error_Message_Title,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
private bool deleteProjectLayers()
|
|
{
|
|
var success = false;
|
|
|
|
try
|
|
{
|
|
if (this.ValidateUpdate())
|
|
{
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = this.Project.ProjectId,
|
|
ProjectName = txtProjectName.Text.Trim(),
|
|
};
|
|
|
|
var flag = this.projectService.DeleteProjectLayers(this.Project.ProjectId);
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(
|
|
this._errorMessage,
|
|
Resources.Registration_Error_Message_Title,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
|
|
private bool deleteProject()
|
|
{
|
|
var success = false;
|
|
|
|
deleteProjectColorProfiles();
|
|
deleteProjectLayers();
|
|
|
|
try
|
|
{
|
|
//if (this.ValidateUpdate())
|
|
//{
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = this.Project.ProjectId,
|
|
ProjectName = txtProjectName.Text.Trim(),
|
|
};
|
|
|
|
var flag = this.projectService.DeleteProject(this.Project.ProjectId);
|
|
|
|
if (flag)
|
|
{
|
|
DataTable data = this.projectService.GetAllProjects();
|
|
success = true;
|
|
}
|
|
//}
|
|
//else
|
|
//{
|
|
// MessageBox.Show(
|
|
// this._errorMessage,
|
|
// Resources.Registration_Error_Message_Title,
|
|
// MessageBoxButtons.OK,
|
|
// MessageBoxIcon.Error);
|
|
//}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
public void LoadProject(int Id)
|
|
{
|
|
DataRow dataRow = this.projectService.GetProjectById(Id);
|
|
|
|
// Assign the values to the model
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = Convert.ToInt16(dataRow["Id"]),
|
|
ProjectName = dataRow["ProjectName"].ToString(),
|
|
OutPath = dataRow["OutPath"].ToString(),
|
|
//Author = this.textBoxAuthor.Text.Trim(),
|
|
CreatedDate = Convert.ToDateTime(dataRow["Created"]),
|
|
LastUpdatedDate = Convert.ToDateTime(dataRow["LastUpdated"]),
|
|
HologramWidth = Convert.ToDouble(dataRow["HologramWidth"]),
|
|
HologramHeight = Convert.ToDouble(dataRow["HologramHeight"]),
|
|
FrameWidth = Convert.ToDouble(dataRow["FrameWidth"]),
|
|
FrameHeight = Convert.ToDouble(dataRow["FrameHeight"]),
|
|
FrameResolutionX = Convert.ToInt16(dataRow["FrameResolutionX"]),
|
|
FrameResolutionY = Convert.ToInt16(dataRow["FrameResolutionY"]),
|
|
GrayRangeLow = Convert.ToInt16(dataRow["GrayRangeLow"]),
|
|
GrayRangeHigh = Convert.ToInt16(dataRow["GrayRangeHigh"]),
|
|
};
|
|
|
|
_project = new Project(projectModel);
|
|
|
|
DataTable data = this.projectService.GetProjectLayers(projectModel.Id);
|
|
DataRow[] rows = data.Select(); // ("ParentID=" + 0);
|
|
|
|
|
|
foreach (DataRow row in rows)
|
|
{
|
|
// Assign the values to the model
|
|
LayerModel layerModel = new LayerModel()
|
|
{
|
|
Id = Convert.ToInt16(row["Id"]),
|
|
Order = Convert.ToInt16(row["Order"]),
|
|
LayerName = row["LayerName"].ToString(),
|
|
OpticalSchema = row["OpticalSchema"].ToString(),
|
|
ProjectId = Convert.ToInt16(row["ProjectId"]),
|
|
TechnologyName = row["TechnologyName"].ToString(),
|
|
SourceFilePath = row["SourceFilePath"].ToString(),
|
|
AnglesFilePath = row["AnglesFilePath"].ToString(),
|
|
LayerLeft = Convert.ToSingle(row["LayerLeft"]),
|
|
LayerTop = Convert.ToSingle(row["LayerTop"]),
|
|
LayerWidth = Convert.ToSingle(row["LayerWidth"]),
|
|
LayerHeight = Convert.ToSingle(row["LayerHeight"]),
|
|
RadiusMax = Convert.ToSingle(row["RadiusMax"]),
|
|
ArcWidth = Convert.ToInt16(row["ArcWidth"]),
|
|
Step = Convert.ToSingle(row["Step"]),
|
|
};
|
|
|
|
projectModel.Layers.Add(layerModel);
|
|
_project.Layers.Add(new Layer(layerModel));
|
|
}
|
|
|
|
|
|
this.txtProjectName.Text = dataRow["ProjectName"].ToString();
|
|
this.txtOutPath.Text = dataRow["OutPath"].ToString();
|
|
this.txtHologW.Text = dataRow["HologramWidth"].ToString();
|
|
this.txtHologH.Text = dataRow["HologramHeight"].ToString();
|
|
this.FrameWidth = Convert.ToSingle(dataRow["FrameWidth"]);
|
|
this.FrameHeight = Convert.ToSingle(dataRow["FrameHeight"]);
|
|
this.ResolutionX = (int)dataRow["FrameResolutionX"];
|
|
this.ResolutionY = (int)dataRow["FrameResolutionY"];
|
|
this.numUpDownGrayLow.Value = (int)dataRow["GrayRangeLow"];
|
|
this.numUpDownGrayHigh.Value = (int)dataRow["GrayRangeHigh"];
|
|
|
|
SetCmbResolution();
|
|
}
|
|
|
|
private void LoadProjectByName(string projectName)
|
|
{
|
|
DataRow dataRow = this.projectService.GetProjectByName(projectName);
|
|
|
|
// Assign the values to the model
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = Convert.ToInt16(dataRow["Id"]),
|
|
ProjectName = dataRow["ProjectName"].ToString(),
|
|
OutPath = dataRow["OutPath"].ToString(),
|
|
//Author = this.textBoxAuthor.Text.Trim(),
|
|
CreatedDate = Convert.ToDateTime(dataRow["Created"]),
|
|
LastUpdatedDate = Convert.ToDateTime(dataRow["LastUpdated"]),
|
|
HologramWidth = Convert.ToDouble(dataRow["HologramWidth"]),
|
|
HologramHeight = Convert.ToDouble(dataRow["HologramHeight"]),
|
|
FrameWidth = Convert.ToDouble(dataRow["FrameWidth"]),
|
|
FrameHeight = Convert.ToDouble(dataRow["FrameHeight"]),
|
|
FrameResolutionX = Convert.ToInt16(dataRow["FrameResolutionX"]),
|
|
FrameResolutionY = Convert.ToInt16(dataRow["FrameResolutionY"]),
|
|
GrayRangeLow = Convert.ToInt16(dataRow["GrayRangeLow"]),
|
|
GrayRangeHigh = Convert.ToInt16(dataRow["GrayRangeHigh"]),
|
|
};
|
|
|
|
DataTable data = this.projectService.GetProjectLayers(projectModel.Id);
|
|
DataRow[] rows = data.Select(); // ("ParentID=" + 0);
|
|
|
|
foreach (DataRow row in rows)
|
|
{
|
|
// Assign the values to the model
|
|
LayerModel layerModel = new LayerModel()
|
|
{
|
|
Id = Convert.ToInt16(row["Id"]),
|
|
Order = Convert.ToInt16(row["Order"]),
|
|
LayerName = row["LayerName"].ToString(),
|
|
OpticalSchema = row["OpticalSchema"].ToString(),
|
|
ProjectId = Convert.ToInt16(row["ProjectId"]),
|
|
TechnologyName = row["TechnologyName"].ToString(),
|
|
SourceFilePath = dataRow["SourceFilePath"].ToString(),
|
|
AnglesFilePath = dataRow["AnglesFilePath"].ToString(),
|
|
RadiusMax = Convert.ToSingle(dataRow["RadiusMax"]),
|
|
ArcWidth = Convert.ToInt16(dataRow["ArcWidth"]),
|
|
Step = Convert.ToSingle(dataRow["Step"]),
|
|
};
|
|
|
|
projectModel.Layers.Add(layerModel);
|
|
//Layer layer = new Layer(layerModel);
|
|
}
|
|
|
|
_project = new Project(projectModel);
|
|
|
|
this.txtProjectName.Text = dataRow["ProjectName"].ToString();
|
|
this.txtOutPath.Text = dataRow["OutPath"].ToString();
|
|
this.txtHologW.Text = dataRow["HologramWidth"].ToString();
|
|
this.txtHologH.Text = dataRow["HologramHeight"].ToString();
|
|
this.txtFrameW.Text = dataRow["FrameWidth"].ToString();
|
|
this.txtFrameH.Text = dataRow["FrameHeight"].ToString();
|
|
//this.numUpDownResX.Value = (int)dataRow["FrameResolutionX"]; !!!!
|
|
//this.numUpDownResY.Value = (int)dataRow["FrameResolutionY"];
|
|
this.numUpDownGrayLow.Value = (int)dataRow["GrayRangeLow"];
|
|
this.numUpDownGrayHigh.Value = (int)dataRow["GrayRangeHigh"];
|
|
}
|
|
|
|
public bool RegisterDefaultProject()
|
|
{
|
|
var success = false;
|
|
try
|
|
{
|
|
cmbResolution_SelectedIndexChanged(this, EventArgs.Empty);
|
|
|
|
// Assign the values to the model
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = 0,
|
|
ProjectName = Resources.Auto_Created_Project_Name,
|
|
OutPath = this.txtOutPath.Text.Trim(),
|
|
CreatedDate = DateTime.Now,
|
|
LastUpdatedDate = DateTime.Now,
|
|
HologramWidth = double.Parse(txtHologW.Text, CultureInfo.InvariantCulture),
|
|
HologramHeight = double.Parse(txtHologH.Text, CultureInfo.InvariantCulture),
|
|
FrameWidth = this.FrameWidth,
|
|
FrameHeight = this.FrameHeight,
|
|
FrameResolutionX = (int)ResolutionX,
|
|
FrameResolutionY = (int)ResolutionY,
|
|
GrayRangeLow = Convert.ToInt16(numUpDownGrayLow.Value, CultureInfo.InvariantCulture),
|
|
GrayRangeHigh = Convert.ToInt16(numUpDownGrayHigh.Value, CultureInfo.InvariantCulture),
|
|
};
|
|
|
|
// Call the service method and assign the return status to variable
|
|
success = this.projectService.RegisterProject(projectModel);
|
|
|
|
// if status of success variable is true then display a information else display the error message
|
|
if (success)
|
|
{
|
|
_project = new Project(projectModel);
|
|
this.ProjectId = projectModel.Id;
|
|
}
|
|
else
|
|
{
|
|
// display the error messge
|
|
MessageBox.Show(
|
|
Resources.Registration_Error_Message,
|
|
Resources.Registration_Error_Message_Title,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
|
|
private bool RegisterNewProject()
|
|
{
|
|
var success = false;
|
|
try
|
|
{
|
|
// Check if the validation passes
|
|
if (this.ValidateRegistration())
|
|
{
|
|
cmbResolution_SelectedIndexChanged(this, EventArgs.Empty);
|
|
|
|
// Assign the values to the model
|
|
ProjectModel projectModel = new ProjectModel()
|
|
{
|
|
Id = 0,
|
|
ProjectName = this.txtProjectName.Text.Trim(),
|
|
OutPath = this.txtOutPath.Text.Trim(),
|
|
CreatedDate = DateTime.Now,
|
|
LastUpdatedDate = DateTime.Now,
|
|
HologramWidth = double.Parse(txtHologW.Text, CultureInfo.InvariantCulture),
|
|
HologramHeight = double.Parse(txtHologH.Text, CultureInfo.InvariantCulture),
|
|
FrameWidth = this.FrameWidth,
|
|
FrameHeight = this.FrameHeight,
|
|
FrameResolutionX = (int)ResolutionX,
|
|
FrameResolutionY = (int)ResolutionY,
|
|
GrayRangeLow = Convert.ToInt16(numUpDownGrayLow.Value, CultureInfo.InvariantCulture),
|
|
GrayRangeHigh = Convert.ToInt16(numUpDownGrayHigh.Value, CultureInfo.InvariantCulture),
|
|
};
|
|
|
|
// Call the service method and assign the return status to variable
|
|
success = this.projectService.RegisterProject(projectModel);
|
|
|
|
// if status of success variable is true then display a information else display the error message
|
|
if (success)
|
|
{
|
|
_project = new Project(projectModel);
|
|
this.ProjectId = projectModel.Id;
|
|
|
|
// display the message box
|
|
//MessageBox.Show(
|
|
// Resources.Registration_Successful_Message,
|
|
// Resources.Registration_Successful_Message_Title,
|
|
// MessageBoxButtons.OK,
|
|
// MessageBoxIcon.Information);
|
|
|
|
// Reset the screen
|
|
//this.ResetRegistration();
|
|
}
|
|
else
|
|
{
|
|
// display the error messge
|
|
MessageBox.Show(
|
|
Resources.Registration_Error_Message,
|
|
Resources.Registration_Error_Message_Title,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Display the validation failed message
|
|
// MessageBox.Show(
|
|
// this.errorMessage,
|
|
// Resources.Registration_Error_Message_Title,
|
|
// MessageBoxButtons.OK,
|
|
// MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.ShowErrorMessage(ex);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
|
|
private void BtnOk_Click(object sender, EventArgs e)
|
|
{
|
|
System.ComponentModel.CancelEventArgs ee = null;
|
|
|
|
clearErrors();
|
|
|
|
txtProjectName_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtProjectName) != "")
|
|
return;
|
|
txtOutPath_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtOutPath) != "")
|
|
return;
|
|
txtHologW_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtHologW) != "")
|
|
return;
|
|
txtHologH_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtHologH) != "")
|
|
return;
|
|
//txtFrameW_Validating(this, ee);
|
|
//if (errorProvider1.GetError(txtFrameW) != "")
|
|
// return;
|
|
//txtFrameH_Validating(this, ee);
|
|
//if (errorProvider1.GetError(txtFrameH) != "")
|
|
// return;
|
|
numUpDownGrayLow_Validating(this, ee);
|
|
if (errorProvider1.GetError(numUpDownGrayLow) != "")
|
|
return;
|
|
numUpDownGrayHigh_Validating(this, ee);
|
|
if (errorProvider1.GetError(numUpDownGrayHigh) != "")
|
|
return;
|
|
|
|
|
|
bool success = false;
|
|
|
|
if (EditMode == true) //control for update project
|
|
{
|
|
success = UpdateProject();
|
|
}
|
|
else //control for create project
|
|
{
|
|
success = RegisterNewProject();
|
|
}
|
|
|
|
if (success == false)
|
|
return;
|
|
|
|
this.Visible = false;
|
|
|
|
OnOkClicked?.Invoke(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Visible = false;
|
|
}
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
deleteProject();
|
|
this.Visible = false;
|
|
|
|
OnDeleteClicked?.Invoke(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
private void btnOutPath_Click(object sender, EventArgs e)
|
|
{
|
|
string selectedFolder = "";
|
|
|
|
using (var fbd = new FileFolderDialog())
|
|
{
|
|
DialogResult result = fbd.ShowDialog();
|
|
|
|
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
|
|
{
|
|
string path = fbd.SelectedPath;
|
|
|
|
// get the file attributes for file or directory
|
|
FileAttributes attr = File.GetAttributes(path);
|
|
|
|
if (attr.HasFlag(FileAttributes.Directory))
|
|
selectedFolder = fbd.SelectedPath;
|
|
else
|
|
selectedFolder = Path.GetDirectoryName(path);
|
|
|
|
txtOutPath.Text = selectedFolder;
|
|
|
|
fbd.Dispose();
|
|
}
|
|
}
|
|
|
|
System.ComponentModel.CancelEventArgs ee = null;
|
|
clearErrors();
|
|
txtOutPath_Validating(this, ee);
|
|
}
|
|
|
|
private void clearErrors()
|
|
{
|
|
errorProvider1.SetError(txtProjectName, "");
|
|
errorProvider1.SetError(txtOutPath, "");
|
|
errorProvider1.SetError(txtHologW, "");
|
|
errorProvider1.SetError(txtHologH, "");
|
|
//errorProvider1.SetError(txtFrameW, "");
|
|
//errorProvider1.SetError(txtFrameH, "");
|
|
errorProvider1.SetError(numUpDownGrayLow, "");
|
|
errorProvider1.SetError(numUpDownGrayHigh, "");
|
|
}
|
|
|
|
private void btnSaveAsDefault_Click(object sender, EventArgs e)
|
|
{
|
|
System.ComponentModel.CancelEventArgs ee = null;
|
|
|
|
clearErrors();
|
|
|
|
txtOutPath_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtOutPath) != "")
|
|
return;
|
|
txtHologW_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtHologW) != "")
|
|
return;
|
|
txtHologH_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtHologH) != "")
|
|
return;
|
|
//txtFrameW_Validating(this, ee);
|
|
//if (errorProvider1.GetError(txtFrameW) != "")
|
|
// return;
|
|
//txtFrameH_Validating(this, ee);
|
|
//if (errorProvider1.GetError(txtFrameH) != "")
|
|
// return;
|
|
numUpDownGrayLow_Validating(this, ee);
|
|
if (errorProvider1.GetError(numUpDownGrayLow) != "")
|
|
return;
|
|
numUpDownGrayHigh_Validating(this, ee);
|
|
if (errorProvider1.GetError(numUpDownGrayHigh) != "")
|
|
return;
|
|
|
|
UpdateProjectDefault();
|
|
|
|
//this.Visible = false;
|
|
|
|
OnSaveAsDefaultClicked?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
|
|
private void btnRun_Click(object sender, EventArgs e)
|
|
{
|
|
System.ComponentModel.CancelEventArgs ee = null;
|
|
|
|
clearErrors();
|
|
|
|
txtProjectName_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtProjectName) != "")
|
|
return;
|
|
txtOutPath_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtOutPath) != "")
|
|
return;
|
|
txtHologW_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtHologW) != "")
|
|
return;
|
|
txtHologH_Validating(this, ee);
|
|
if (errorProvider1.GetError(txtHologH) != "")
|
|
return;
|
|
//txtFrameW_Validating(this, ee);
|
|
//if (errorProvider1.GetError(txtFrameW) != "")
|
|
// return;
|
|
//txtFrameH_Validating(this, ee);
|
|
//if (errorProvider1.GetError(txtFrameH) != "")
|
|
// return;
|
|
numUpDownGrayLow_Validating(this, ee);
|
|
if (errorProvider1.GetError(numUpDownGrayLow) != "")
|
|
return;
|
|
numUpDownGrayHigh_Validating(this, ee);
|
|
if (errorProvider1.GetError(numUpDownGrayHigh) != "")
|
|
return;
|
|
|
|
}
|
|
|
|
private void txtProjectName_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
errorProvider1.SetError(txtProjectName, "");
|
|
|
|
if (txtProjectName.Text.Trim() == "")
|
|
errorProvider1.SetError(txtProjectName, "Project Name must not be empty.");
|
|
|
|
}
|
|
|
|
private void txtOutPath_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
errorProvider1.SetError(txtOutPath, "");
|
|
|
|
if (txtOutPath.Text.Trim() == "")
|
|
{
|
|
errorProvider1.SetError(txtOutPath, "Output Path must not be empty.");
|
|
return;
|
|
}
|
|
|
|
if (Helper.IsValidPath(txtOutPath.Text.Trim(), false) == false)
|
|
errorProvider1.SetError(txtOutPath, "Output Path is incorrect.");
|
|
|
|
}
|
|
|
|
private void SetCmbResolution()
|
|
{
|
|
string result = "1024 x 768 - 0.2";
|
|
double frameWidthRounded = Math.Round(FrameWidth, 1);
|
|
|
|
if (ResolutionX == 1024 && frameWidthRounded == 0.2)
|
|
{
|
|
result = "1024 x 768 - 0.2";
|
|
} else if (ResolutionX == 1024 && frameWidthRounded == 0.3)
|
|
{
|
|
result = "1024 x 768 - 0.3";
|
|
} else if (ResolutionX == 1920 && frameWidthRounded == 0.3)
|
|
{
|
|
result = "1920 x 1080 - 0.3";
|
|
}
|
|
else if (ResolutionX == 1920 && frameWidthRounded == 0.4)
|
|
{
|
|
result = "1920 x 1080 - 0.4";
|
|
}
|
|
|
|
this.cmbResolution.Text = result;
|
|
}
|
|
|
|
private void cmbResolution_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
string selected = cmbResolution.SelectedItem.ToString();
|
|
|
|
switch (selected)
|
|
{
|
|
case "1024 x 768 - 0.2":
|
|
ResolutionX = 1024;
|
|
ResolutionY = 768;
|
|
FrameWidth = 0.2F;
|
|
FrameHeight = 0.15F;
|
|
break;
|
|
case "1024 x 768 - 0.3":
|
|
ResolutionX = 1024;
|
|
ResolutionY = 768;
|
|
FrameWidth = 0.3F;
|
|
FrameHeight = 0.225F;
|
|
break;
|
|
case "1920 x 1080 - 0.3":
|
|
ResolutionX = 1920;
|
|
ResolutionY = 1080;
|
|
FrameWidth = 0.3F;
|
|
FrameHeight = 0.16875F;
|
|
break;
|
|
case "1920 x 1080 - 0.4":
|
|
ResolutionX = 1920;
|
|
ResolutionY = 1080;
|
|
FrameWidth = 0.4F;
|
|
FrameHeight = 0.225F;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void txtHologW_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
errorProvider1.SetError(txtHologW, "");
|
|
|
|
if (txtHologW.Text.Trim() == "")
|
|
errorProvider1.SetError(txtHologW, "Hologram Width must not be empty.");
|
|
}
|
|
|
|
private void txtHologH_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
errorProvider1.SetError(txtHologH, "");
|
|
|
|
if (txtHologH.Text.Trim() == "")
|
|
errorProvider1.SetError(txtHologH, "Hologram Height must not be empty.");
|
|
}
|
|
|
|
private void txtFrameW_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
errorProvider1.SetError(txtFrameW, "");
|
|
|
|
if (txtFrameW.Text.Trim() == "")
|
|
errorProvider1.SetError(txtFrameW, "Frame Width must not be empty.");
|
|
}
|
|
|
|
private void txtFrameH_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
errorProvider1.SetError(txtFrameH, "");
|
|
|
|
if (txtFrameH.Text.Trim() == "")
|
|
errorProvider1.SetError(txtFrameH, "Frame Height must not be empty.");
|
|
}
|
|
|
|
private void numUpDownGrayLow_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
errorProvider1.SetError(numUpDownGrayLow, "");
|
|
|
|
if (numUpDownGrayLow.Text.Trim() == "0")
|
|
errorProvider1.SetError(numUpDownGrayLow, "Gray Low must not be empty.");
|
|
}
|
|
|
|
private void numUpDownGrayHigh_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
errorProvider1.SetError(numUpDownGrayHigh, "");
|
|
|
|
if (numUpDownGrayHigh.Text.Trim() == "0")
|
|
errorProvider1.SetError(numUpDownGrayHigh, "Gray High must not be empty.");
|
|
}
|
|
|
|
private void btnPreview_Click(object sender, EventArgs e)
|
|
{
|
|
OnPreviewClicked?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|