//action 'Add' new object to grid private void btnAddComplex_Click(object sender, EventArgs e) { //change property 'Text' of the btnSave for 'Add' action btnSaveSystemConstant.Text = "Додати"; //refresh data for field 'Code' systemConstantData = new SystemConstant(); bsSystemConstant.DataSource = systemConstantData; //refresh data for field 'Uk' ukSystemConstant = new SystemConstantTr { Lang = Langs[0] }; systemConstantData.SystemConstantTr.Add(ukSystemConstant); bsUkLangSystemConstant.DataSource = ukSystemConstant; //refresh data for field 'Ru' ruSystemConstant = new SystemConstantTr { Lang = Langs[1] }; systemConstantData.SystemConstantTr.Add(ruSystemConstant); bsRuLangSystemConstant.DataSource = ruSystemConstant; //refresh data for field 'Ru' enSystemConstant = new SystemConstantTr { Lang = Langs[2] }; systemConstantData.SystemConstantTr.Add(enSystemConstant); bsEnLangSystemConstant.DataSource = enSystemConstant; //stop perform if elements have 'Enabled' -> false if (!ControlEnabledActiveElements) { return; } //change 'Enabled' state for elements ControlEnabledActiveElements = false; }
//action 'Delete' exist object from grid private void btnDeleteComplex_Click(object sender, EventArgs e) { //return if element by index is not exist if (!(SystemConstantList.Count > indexSelectedElem)) { return; } //delete selected item of grid by field 'Code' SystemConstant item = SystemConstantList[indexSelectedElem]; bool result = CheckAfterDelete(item.CodeI); //update data for grid gridSystemConstantList.DataSource = HandleDataForGrid(urlDataGrid); //step up in grid position if (result) { --indexSelectedElem; } if (indexSelectedElem < 0) { indexSelectedElem = 0; } gridSystemConstantList.CurrentRow = gridSystemConstantList.Rows[indexSelectedElem]; //define new currentRow DataUpdateForBottomPanel( SystemConstantList[indexSelectedElem].CodeI ); }
/// <summary> /// check result data after 'Update' /// </summary> /// <param name="updateItem"></param> /// <returns></returns> private SystemConstant CheckAfterUpdate(SystemConstant updateItem) { UpdateLayer dictDelegat = new UpdateLayer(_layer.Update); SystemConstant result = dictDelegat(systemConstantData); if (result == null) { MessageBox.Show(UpdateMess); //select first element of grid by default result = SystemConstantList[0]; } return(result); }
/// <summary> /// check result data after 'Craete' /// </summary> /// <param name="createItem"></param> /// <returns></returns> private SystemConstant CheckAfterCreate(SystemConstant createItem) { CreateLayer dictDelegat = new CreateLayer(_layer.Create); SystemConstant result = dictDelegat(createItem); if (result == null) { MessageShow.ShowError(CreateMess); //select first element of grid by default result = SystemConstantList[0]; } return(result); }
/// <summary> /// Delete a piece of SystemConstant record in database. /// </summary> /// <param name="SystemConstant"></param> /// <returns></returns> public Response DeleteSystemConstant(SystemConstant systemConstant) { Response response = new Response(); using (_dataAccess.Connection = new OleDbConnection(ConnectionString)) { _dataAccess.Open(); string sql = "DELETE FROM [SystemConstant] WHERE [SystemConstantId]=@SystemConstantId"; QueryParameter p = new QueryParameter("@SystemConstantId", systemConstant.SystemConstantId, DbType.Int32); response.IsFailed = !Convert.ToBoolean(_dataAccess.ExecuteNonQuery(sql, p)); } return(response); }
/// <summary> /// check after 'Get' query /// </summary> /// <param name="codeI"></param> /// <returns></returns> private SystemConstant CheckAfterGetQuery(int codeI) { GetDictionaryLayer dictDelegat = new GetDictionaryLayer(_layer.GetDictionary); SystemConstant result = dictDelegat(codeI); if (result == null) { MessageShow.ShowError(GetMess); //set select first element of grid result = SystemConstantList[0]; } return(result); }
/// <summary> /// Insert a piece of record in database. /// </summary> /// <param name="SystemConstant"></param> /// <returns></returns> public Response InsertSystemConstant(SystemConstant systemConstant) { Response response = new Response(); using (_dataAccess.Connection = new OleDbConnection(ConnectionString)) { _dataAccess.Open(); string sql = "INSERT INTO [SystemConstant] ([ConstantName],[ConstantValue],[Description]) VALUES (@ConstantName,@ConstantValue,@Description)"; QueryParameter[] list = new QueryParameter[3]; list[0] = new QueryParameter("@ConstantName", systemConstant.ConstantName, DbType.String); list[1] = new QueryParameter("@ConstantValue", systemConstant.ConstantValue, DbType.String); list[2] = new QueryParameter("@Description", systemConstant.Description, DbType.String); response.IsFailed = !Convert.ToBoolean(_dataAccess.ExecuteNonQuery(sql, list)); } return(response); }
/// <summary> /// Update a piece of record in database. /// </summary> /// <param name="SystemConstant"></param> /// <returns></returns> public Response UpdateSystemConstant(SystemConstant systemConstant) { Response response = new Response(); using (_dataAccess.Connection = new OleDbConnection(ConnectionString)) { _dataAccess.Open(); string sql = "UPDATE [SystemConstant] SET [ConstantName]=@ConstantName,[ConstantValue]=@ConstantValue,[Description]=@Description WHERE [SystemConstantId]=@SystemConstantId"; QueryParameter[] list = new QueryParameter[4]; list[0] = new QueryParameter("@ConstantName", systemConstant.ConstantName, DbType.String); list[1] = new QueryParameter("@ConstantValue", systemConstant.ConstantValue, DbType.String); list[2] = new QueryParameter("@Description", systemConstant.Description, DbType.String); list[3] = new QueryParameter("@SystemConstantId", systemConstant.SystemConstantId, DbType.Int32); response.IsFailed = !Convert.ToBoolean(_dataAccess.ExecuteNonQuery(sql, list)); } return(response); }
/// <summary> /// Select a SystemConstant list by SystemConstant name /// </summary> /// <param name="SystemConstant"></param> /// <returns></returns> public SystemConstant GetSystemConstantByConstantName(SystemConstant s) { SystemConstant systemConstant = new SystemConstant(); using (_dataAccess.Connection = new OleDbConnection(ConnectionString)) { _dataAccess.Open(); string sql = "SELECT * FROM [SystemConstant] WHERE ConstantName=@ConstantName"; QueryParameter p = new QueryParameter("SystemConstantName", s.ConstantName, DbType.String); DataTable dt = _dataAccess.GetTable(sql, p); foreach (DataRow dr in dt.Rows) { systemConstant.SystemConstantId = Convert.ToInt32(dr[SystemConstantId]); systemConstant.ConstantName = dr[ConstantName].ToString(); systemConstant.ConstantValue = dr[ConstantValue].ToString(); systemConstant.Description = dr[Description].ToString(); } } return(systemConstant); }
//action 'Save' object to grid private void btnSave_Click(object sender, EventArgs e) { //refresh bottom panel int codeIAfter = 0; if (btnSaveSystemConstant.Text == "Додати") { //send created object SystemConstant result = CheckAfterCreate(systemConstantData); codeIAfter = result.CodeI; //update data for grid gridSystemConstantList.DataSource = HandleDataForGrid(urlDataGrid); indexSelectedElem = _systemConstantList.FindIndex(el => el.CodeI == result.CodeI); //select certain item into grid gridSystemConstantList.CurrentRow = gridSystemConstantList.Rows[indexSelectedElem]; btnSaveSystemConstant.Text = "Зберегти"; } else if (btnSaveSystemConstant.Text == "Зберегти") { //save changes SystemConstant result = CheckAfterUpdate(systemConstantData); codeIAfter = result.CodeI; //save last selected item indexSelectedElem = gridSystemConstantList.CurrentRow.Index; //update data for grid gridSystemConstantList.DataSource = HandleDataForGrid(urlDataGrid); //select certain item into grid gridSystemConstantList.CurrentRow = gridSystemConstantList.Rows[indexSelectedElem]; } DataUpdateForBottomPanel(codeIAfter); //stop perform if elements have 'Enabled' -> true if (ControlEnabledActiveElements) { return; } //change 'Enabled' state for elements ControlEnabledActiveElements = true; }
/// <summary> /// Select All records /// </summary> /// <returns></returns> public List <SystemConstant> GetAllSystemConstants() { List <SystemConstant> systemConstantList = new List <SystemConstant>(); using (_dataAccess.Connection = new OleDbConnection(ConnectionString)) { _dataAccess.Open(); string sql = "SELECT * FROM [SystemConstant] "; DataTable dt = _dataAccess.ExecuteSql(sql); foreach (DataRow dr in dt.Rows) { SystemConstant SystemConstant = new SystemConstant() { SystemConstantId = Convert.ToInt32(dr[SystemConstantId]), ConstantName = dr[ConstantName].ToString(), ConstantValue = dr[ConstantValue].ToString(), Description = dr[Description].ToString(), }; systemConstantList.Add(SystemConstant); } } return(systemConstantList); }
//refresh changed data for bottom panel private void DataUpdateForBottomPanel(int codeI) { //get object by parameter 'code' from service systemConstantData = CheckAfterGetQuery(codeI); //use data for binding source bsSystemConstant.DataSource = systemConstantData; //define binding for source of the 'Uk' ukSystemConstant = systemConstantData.SystemConstantTr.FirstOrDefault(rec => rec.Lang == Langs[0]); if (ukSystemConstant == null) { ukSystemConstant = new SystemConstantTr { Lang = Langs[0] }; systemConstantData.SystemConstantTr.Add(ukSystemConstant); } bsUkLangSystemConstant.DataSource = ukSystemConstant; //defined binding for source of the 'Ru' ruSystemConstant = systemConstantData.SystemConstantTr.FirstOrDefault(rec => rec.Lang == Langs[1]); if (ruSystemConstant == null) { ruSystemConstant = new SystemConstantTr { Lang = Langs[1] }; systemConstantData.SystemConstantTr.Add(ruSystemConstant); } bsRuLangSystemConstant.DataSource = ruSystemConstant; //define binding for source of the 'En' enSystemConstant = systemConstantData.SystemConstantTr.FirstOrDefault(rec => rec.Lang == Langs[2]); if (enSystemConstant == null) { enSystemConstant = new SystemConstantTr { Lang = Langs[2] }; systemConstantData.SystemConstantTr.Add(enSystemConstant); } bsEnLangSystemConstant.DataSource = enSystemConstant; }
/// <summary> /// Updates the system constant. /// </summary> /// <param name="sc">The sc.</param> public void UpdateSystemConstant(SystemConstant sc) { new SystemConstantRepository().UpdateSystemConstant(sc); }
//预览功能 private void PreviewControler() { float X = this.panel1.Size.Width ; X = X / 373; float Y = this.panel1.Size.Height ; Y = Y / 245; X =Math.Max(1F, Math.Min(2F, Math.Min(X, Y))); panel1.Controls.Clear(); Point XY = new Point(this.panel1.Size.Width / 5 - 10, this.panel1.Size.Height / 6);//定位 Point YX = new Point(this.panel1.Size.Width / 4 - 40, this.panel1.Size.Height / 3 - 15); if (Basic[7] == "Modules") { Modules controler = new Modules(); controler.Location = XY; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "Arithmetic") { //ControlTactic.SpecialControl.Fuzzy fuzzy = new ControlTactic.SpecialControl.Fuzzy(); Arithmetic controler = new Arithmetic(); controler.Location = XY; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "OutputValue") { OutputValue controler = new OutputValue(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "InputValue") { InputValue controler = new InputValue(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "Constant") { Constant controler = new Constant(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "SystemConstant") { SystemConstant controler = new SystemConstant(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "Lable") { ControlTactic.Label controler = new ControlTactic.Label(); controler.Location = YX; SetVelue(controler); controler.Scaling = 1.8F * X; panel1.Controls.Add(controler); } else if (Basic[7] == "JMP") { ControlTactic.JMP controler = new ControlTactic.JMP(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } }
//预览功能 private void PreviewControler() { float X = this.panel1.Size.Width; X = X / 373; float Y = this.panel1.Size.Height; Y = Y / 245; X = Math.Max(1F, Math.Min(2F, Math.Min(X, Y))); panel1.Controls.Clear(); Point XY = new Point(this.panel1.Size.Width / 5 - 10, this.panel1.Size.Height / 6);//定位 Point YX = new Point(this.panel1.Size.Width / 4 - 40, this.panel1.Size.Height / 3 - 15); if (Basic[7] == "Modules") { Modules controler = new Modules(); controler.Location = XY; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "Arithmetic") { //ControlTactic.SpecialControl.Fuzzy fuzzy = new ControlTactic.SpecialControl.Fuzzy(); Arithmetic controler = new Arithmetic(); controler.Location = XY; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "OutputValue") { OutputValue controler = new OutputValue(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "InputValue") { InputValue controler = new InputValue(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "Constant") { Constant controler = new Constant(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "SystemConstant") { SystemConstant controler = new SystemConstant(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } else if (Basic[7] == "Lable") { ControlTactic.Label controler = new ControlTactic.Label(); controler.Location = YX; SetVelue(controler); controler.Scaling = 1.8F * X; panel1.Controls.Add(controler); } else if (Basic[7] == "JMP") { ControlTactic.JMP controler = new ControlTactic.JMP(); controler.Location = YX; SetVelue(controler); controler.Scaling = X; panel1.Controls.Add(controler); } }