예제 #1
0
        /// <summary>
        /// delete column
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 删除列
        private void tsbDelete_Click(object sender, EventArgs e)
        {
            //add rows
            if (MessageService.AskQuestion(StringParser.Parse("${res:FanHai.Hemera.Addins.Msg.DeleteRemind}"), StringParser.Parse("${res:Global.SystemInfo}")))
            {
                if (this.dgvData.Rows.Count > 0)
                {
                    //get selected row in datagrid
                    int selectedLineNumber = GetSelectedRowIndex(this.dgvData);
                    //if there are no selected rows
                    if (selectedLineNumber == -1)
                    {
                        MessageBox.Show(StringParser.Parse("${res:FanHai.Hemera.Addins.BasicData.BasicSettingsDetail.MsgWetherSelectOneEditedRow}"));
                        return;
                    }
                    //if select ok
                    if (MessageBox.Show(StringParser.Parse("${res:FanHai.Hemera.Addins.BasicData.BasicSettingsDetail.MsgDeleteDataText}"), StringParser.Parse("${res:FanHai.Hemera.Addins.BasicData.BasicSettingsDetail.MsgDeleteDataCaption}"), MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        //get attribute key
                        string attributeKey = dgvData.Rows[selectedLineNumber].Cells["ColumnKey"].Value.ToString();
                        //set entity's attribute
                        baseAttributeEntity.AttributeKey = attributeKey;

                        try
                        {
                            //delete data
                            baseAttributeEntity.DeleteBaseAttribute();
                            //check result
                            if (baseAttributeEntity.ErrorMsg == "")
                            {
                                //delete row from datagridview
                                this.dgvData.Rows.RemoveAt(selectedLineNumber);
                                MessageBox.Show(StringParser.Parse("${res:FanHai.Hemera.Addins.BasicData.BasicSettingsDetail.MsgDeleteDataSuccessfully}"));
                            }
                            else
                            {
                                MessageBox.Show(StringParser.Parse(baseAttributeEntity.ErrorMsg));
                            }
                        }
                        catch (Exception ee)
                        {
                            MessageBox.Show(ee.Message);
                        }
                    }
                }
            }
        }