public int InsertUnitRow(EntityUnit entity)
        {
            string SqlStr = "";

            SqlStr  = "insert into tc_unit(unit_code,unit_name,unit_yxm)";
            SqlStr += " values('" + entity.Unit_code.Trim() + "','" + entity.Unit_name.Trim() + "','" + entity.Unit_yxm.Trim() + "')";

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = SqlStr;

            ExcuteSql(sqlCommand);

            return(Constants.SystemConfig.SERVER_SUCCESS);
        }
Beispiel #2
0
        public int DeleteUnit(EntityUnit entUnit)
        {
            int cnt = 0;

            try
            {
                List <SqlParameter> lstParam = new List <SqlParameter>();
                Commons.ADDParameter(ref lstParam, "@PKId", DbType.Int32, entUnit.PKId);
                cnt = mobjDataAcces.ExecuteQuery("sp_DeleteUnit", lstParam);
            }
            catch (Exception ex)
            {
                Commons.FileLog("UnitBLL - DeleteUnit(EntityUnit entUnit)", ex);
            }
            return(cnt);
        }
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            int        lintcnt = 0;
            EntityUnit entUnit = new EntityUnit();

            if (string.IsNullOrEmpty(txtUnitCode.Text.Trim()))
            {
                lblMsg.Text = "Please Enter Unit Code";
            }
            else
            {
                if (string.IsNullOrEmpty(txtUnitDesc.Text.Trim()))
                {
                    lblMsg.Text = " Enter Unit Description";
                    txtUnitDesc.Focus();
                    return;
                }
                else
                {
                    entUnit.UnitCode = txtUnitCode.Text.Trim();
                    entUnit.UnitDesc = txtUnitDesc.Text.Trim();

                    if (!Commons.IsRecordExists("tblUnitMaster", "UnitDesc", Convert.ToString(entUnit.UnitDesc)))
                    {
                        lintcnt = mobjUnitBLL.InsertUnit(entUnit);

                        if (lintcnt > 0)
                        {
                            GetUnits();
                            lblMessage.Text = "Record Inserted Successfully";
                            // this.programmaticModalPopup.Hide();
                        }
                        else
                        {
                            lblMessage.Text = "Record Not Inserted";
                        }
                    }
                    else
                    {
                        lblMessage.Text = "Record Already Exist";
                    }
                }
            }
            MultiView1.SetActiveView(View1);
        }
Beispiel #4
0
        public int UpdateUnit(EntityUnit entUnit)
        {
            int cnt = 0;

            try
            {
                List <SqlParameter> lstParam = new List <SqlParameter>();
                Commons.ADDParameter(ref lstParam, "@UnitCode", DbType.String, entUnit.UnitCode);
                Commons.ADDParameter(ref lstParam, "@UnitDesc", DbType.String, entUnit.UnitDesc);

                cnt = mobjDataAcces.ExecuteQuery("sp_UpdateUnit", lstParam);
            }
            catch (Exception ex)
            {
                Commons.FileLog("UnitBLL -  UpdateUnit(EntityUnit entUnit)", ex);
            }
            return(cnt);
        }
        protected void BtnDeleteOk_Click(object sender, EventArgs e)
        {
            EntityUnit entUnit = new EntityUnit();
            int        cnt     = 0;

            try
            {
                foreach (GridViewRow drv in dgvUnit.Rows)
                {
                    CheckBox chkDelete = (CheckBox)drv.FindControl("chkDelete");
                    if (chkDelete.Checked)
                    {
                        LinkButton lnkUnitCode  = (LinkButton)drv.FindControl("lnkUnitCode");
                        string     lstrUnitCode = lnkUnitCode.Text;
                        entUnit.UnitCode = lstrUnitCode;
                        cnt = mobjUnitBLL.DeleteUnit(entUnit);
                        if (cnt > 0)
                        {
                            //this.modalpopupDelete.Hide();
                            lblMessage.Text = "Record Deleted Successfully....";
                            if (dgvUnit.Rows.Count <= 0)
                            {
                                pnlShow.Style.Add(HtmlTextWriterStyle.Display, "none");
                                hdnPanel.Value = "none";
                            }
                        }
                        else
                        {
                            lblMessage.Text = "Record Not Deleted....";
                        }
                    }
                }
                GetUnits();
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Commons.FileLog("frmUnitMaster -   BtnDeleteOk_Click(object sender, EventArgs e)", ex);
            }
        }
Beispiel #6
0
        public int UpdateUnitTable(EntityUnit entity)
        {
            string SqlStr = "";

            SqlStr = "update tc_unit set ";

            SqlStr += "unit_name = '" + entity.Unit_name.Trim() + "' ";

            SqlStr += ",unit_yxm = '" + entity.Unit_yxm.Trim() + "' ";

            SqlStr += " where unit_code= '" + entity.Unit_code.Trim() + "' ";

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = SqlStr;

            ExcuteSql(sqlCommand);

            return(Constants.SystemConfig.SERVER_SUCCESS);
        }
Beispiel #7
0
        //***********************************************************************
        /// <summary>
        /// 保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        ///    完成信息:代国明      2010/07/15 完成
        ///    更新信息:
        /// </history>
        //***********************************************************************
        private void btnSave_Click(object sender, EventArgs e)
        {
            foreach (Control control in groupBox1.Controls)
            {
                if (control is TextBox)
                {
                    if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly)
                    {
                        MessageBox.Show("不可以输入非法字符,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        control.Focus();
                        return;
                    }
                }
            }

            if (this.txt_unit_name.Text.Trim() == string.Empty)
            {
                MessageBox.Show("计量单位不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_unit_name.Focus();
                return;
            }

            try
            {
                result = -1;

                //如果是添加
                if (dataType == DataType.Insert)
                {
                    //取得实体类
                    unitEntity = new EntityUnit();

                    //赋值实体类
                    unitEntity.Unit_name = this.txt_unit_name.Text.ToString().Trim();
                    unitEntity.Unit_yxm  = this.txt_unit_yxm.Text.ToString().Trim();

                    //打开数据库连接
                    dataAccess = new DataAccess();
                    dataAccess.Open();

                    MakePrimaryKey mpk = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction);
                    unitEntity.Unit_code = mpk.MakeCode("计量单位");

                    //取得操作类
                    GetData getData = new GetData(dataAccess.Connection);

                    if (getData.InsertIsOnly("tc_unit", "unit_name", txt_unit_name.Text.ToString()))
                    {
                        MessageBox.Show("您输入的计量单位已经存在!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txt_unit_name.Focus();
                        return;
                    }

                    //取得结果符
                    result = getData.InsertUnitRow(unitEntity);

                    if (result == 0)
                    {
                        MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("操作添加时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                //如果是更新
                else if (dataType == DataType.Update)
                {
                    countNum = dgvUnit.SelectedRows[0].Index;
                    //取得树体类
                    unitEntity = new EntityUnit();

                    //赋值实体类
                    unitEntity.Unit_code = dgvUnit.SelectedRows[0].Cells["unit_code"].Value.ToString();
                    unitEntity.Unit_name = txt_unit_name.Text.ToString().Trim();
                    unitEntity.Unit_yxm  = txt_unit_yxm.Text.ToString().Trim();

                    //打开数据库连接
                    dataAccess = new DataAccess();
                    dataAccess.Open();

                    //打开事务
                    dataAccess.BeginTransaction();

                    //取得操作类
                    GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction);

                    if (getData.UpdateIsOnly("tc_unit", "unit_code", unitEntity.Unit_code, "unit_name", txt_unit_name.Text.ToString()))
                    {
                        MessageBox.Show("您输入的计量单位已经存在!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txt_unit_name.Focus();
                        return;
                    }

                    //取得结果符
                    result = getData.UpdateUnitTable(unitEntity);

                    if (result == 0)
                    {
                        MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("操作添加时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    //提交事务
                    dataAccess.Commit();
                }
            }
            catch (Exception ex)
            {
                if (dataAccess.Transaction != null)
                {
                    //回滚
                    dataAccess.Rollback();
                }

                //提示错误
                MessageBox.Show("数据添加时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                //关闭数据库连接
                dataAccess.Close();

                //设置按钮状态
                dataType = DataType.None;
                setButtonState();

                //重新加载画面
                BandingDgvUnit();
            }
        }