Example #1
0
 private void dgvCellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex < 0)
     {
         return;
     }
     optrowid = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
     if (!String.IsNullOrEmpty(optrowid))
     {
         model = dal.GetModel(int.Parse(optrowid));
         if (model != null)
         {
             BLL.tb_proc   dalp = new BLL.tb_proc();
             Model.tb_proc molp = new Model.tb_proc();
             molp                         = dalp.GetModel(int.Parse(model.cr_pid.ToString()));
             this.txtno.Text              = molp.p_no;
             this.txtname.Text            = molp.p_name;
             this.txttyid.Text            = model.cr_pid.ToString();
             this.txtorder.SelectedValue  = model.cr_oid.ToString();
             this.txtprice.Text           = model.cr_price.ToString();
             this.txtrek.Text             = model.cr_remark;
             this.txtnum.Text             = model.cr_num.ToString();
             this.txtstatus.SelectedValue = model.cr_yan.ToString();
         }
     }
 }
Example #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.tb_churu GetModel(int cr_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1  ");
            strSql.Append(" cr_id,cr_oid,cr_pid,cr_time,cr_type,cr_num,cr_yan,cr_price,cr_remark ");
            strSql.Append(" from tb_churu ");
            strSql.Append(" where cr_id=" + cr_id + "");
            Model.tb_churu model = new Model.tb_churu();
            DataSet        ds    = DbSQL.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["cr_id"] != null && ds.Tables[0].Rows[0]["cr_id"].ToString() != "")
                {
                    model.cr_id = int.Parse(ds.Tables[0].Rows[0]["cr_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cr_oid"] != null && ds.Tables[0].Rows[0]["cr_oid"].ToString() != "")
                {
                    model.cr_oid = int.Parse(ds.Tables[0].Rows[0]["cr_oid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cr_pid"] != null && ds.Tables[0].Rows[0]["cr_pid"].ToString() != "")
                {
                    model.cr_pid = int.Parse(ds.Tables[0].Rows[0]["cr_pid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cr_time"] != null && ds.Tables[0].Rows[0]["cr_time"].ToString() != "")
                {
                    model.cr_time = ds.Tables[0].Rows[0]["cr_time"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cr_type"] != null && ds.Tables[0].Rows[0]["cr_type"].ToString() != "")
                {
                    model.cr_type = int.Parse(ds.Tables[0].Rows[0]["cr_type"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cr_num"] != null && ds.Tables[0].Rows[0]["cr_num"].ToString() != "")
                {
                    model.cr_num = int.Parse(ds.Tables[0].Rows[0]["cr_num"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cr_yan"] != null && ds.Tables[0].Rows[0]["cr_yan"].ToString() != "")
                {
                    model.cr_yan = int.Parse(ds.Tables[0].Rows[0]["cr_yan"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cr_price"] != null && ds.Tables[0].Rows[0]["cr_price"].ToString() != "")
                {
                    model.cr_price = decimal.Parse(ds.Tables[0].Rows[0]["cr_price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cr_remark"] != null && ds.Tables[0].Rows[0]["cr_remark"].ToString() != "")
                {
                    model.cr_remark = ds.Tables[0].Rows[0]["cr_remark"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        private void tbBtnClick(object sender, ToolBarButtonClickEventArgs e)
        {
            if (e.Button.ToolTipText == "新增")
            {
                rstValue();
                setModifyMode(true);
                optrowid = null;
            }
            if (e.Button.ToolTipText == "修改")
            {
                if (!String.IsNullOrEmpty(optrowid))
                {
                    setModifyMode(true);
                }
                else
                {
                    MessageBox.Show("请选择所要修改的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            if (e.Button.ToolTipText == "删除")
            {
                if (!String.IsNullOrEmpty(optrowid))
                {
                    DialogResult result = MessageBox.Show("确认删除?", "删除数据", MessageBoxButtons.OKCancel);
                    if (result == DialogResult.OK)
                    {
                        dal.Delete(int.Parse(optrowid));
                        rstValue();
                        MessageBox.Show("恭喜你,删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        bindData("cr_type=1");
                        setModifyMode(false);
                        optrowid = null;
                    }
                }
                else
                {
                    MessageBox.Show("请选择所要删除的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            if (e.Button.ToolTipText == "提交")
            {
                if (ValidateIput())
                {
                    model = new Model.tb_churu();

                    if (!string.IsNullOrEmpty(optrowid))
                    {
                        model = dal.GetModel(int.Parse(optrowid));
                    }
                    model.cr_oid    = int.Parse(this.txtorder.SelectedValue.ToString());
                    model.cr_pid    = int.Parse(txttyid.Text);
                    model.cr_price  = decimal.Parse(txtprice.Text);
                    model.cr_remark = txtrek.Text;
                    model.cr_type   = 1;
                    model.cr_yan    = int.Parse(this.txtstatus.SelectedValue.ToString());
                    int tempNum = int.Parse(this.txtnum.Text);
                    if (tempNum <= 0)
                    {
                        MessageBox.Show("输入数量有误,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    model.cr_num = tempNum;
                    if (String.IsNullOrEmpty(optrowid))
                    {
                        model.cr_time = System.DateTime.Now.ToString("yyyy-MM-dd");
                        if (dal.Add(model) > 0)
                        {
                            BLL.tb_proc   dap = new BLL.tb_proc();
                            Model.tb_proc mop = new Model.tb_proc();
                            mop = dap.GetModel(int.Parse(txttyid.Text));
                            if (model.cr_yan == 1)
                            {
                                mop.p_num = mop.p_num + int.Parse(this.txtnum.Text); //验收状态:是
                            }
                            else
                            {
                                mop.p_num = mop.p_num + 0; //验收状态:否
                            }
                            if (!string.IsNullOrEmpty(mop.p_sx))
                            {
                                if (mop.p_num > int.Parse(mop.p_sx))
                                {
                                    MessageBox.Show("已超过库存预警上限,请更换", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    return;
                                }
                            }
                            dap.Update(mop);
                            if (model.cr_yan == 1)
                            {
                                MessageBox.Show("恭喜你,验收入库成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //验收状态:是
                            }
                            else
                            {
                                MessageBox.Show("商品验收入库失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //验收状态:否
                            }
                            rstValue();
                            bindData("cr_type=1");
                            setModifyMode(false);
                            optrowid = null;
                        }
                    }
                    else
                    {
                        if (dal.Update(model))
                        {
                            MessageBox.Show("恭喜你,修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            rstValue();
                            bindData("cr_type=1");
                            setModifyMode(false);
                            optrowid = null;
                        }
                    }
                }
            }

            if (e.Button.ToolTipText == "取消")
            {
                bindData("cr_type=1");
                rstValue();
                setModifyMode(false);
                optrowid = null;
            }

            if (e.Button.ToolTipText == "退出")
            {
                this.Close();
            }
        }
Example #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.tb_churu model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.cr_oid != null)
            {
                strSql1.Append("cr_oid,");
                strSql2.Append("" + model.cr_oid + ",");
            }
            if (model.cr_pid != null)
            {
                strSql1.Append("cr_pid,");
                strSql2.Append("" + model.cr_pid + ",");
            }
            if (model.cr_time != null)
            {
                strSql1.Append("cr_time,");
                strSql2.Append("'" + model.cr_time + "',");
            }
            if (model.cr_type != null)
            {
                strSql1.Append("cr_type,");
                strSql2.Append("" + model.cr_type + ",");
            }
            if (model.cr_num != null)
            {
                strSql1.Append("cr_num,");
                strSql2.Append("" + model.cr_num + ",");
            }
            if (model.cr_yan != null)
            {
                strSql1.Append("cr_yan,");
                strSql2.Append("" + model.cr_yan + ",");
            }
            if (model.cr_price != null)
            {
                strSql1.Append("cr_price,");
                strSql2.Append("" + model.cr_price + ",");
            }
            if (model.cr_remark != null)
            {
                strSql1.Append("cr_remark,");
                strSql2.Append("'" + model.cr_remark + "',");
            }
            strSql.Append("insert into tb_churu(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DbSQL.GetSingle(strSql.ToString());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.tb_churu model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_churu set ");
            if (model.cr_oid != null)
            {
                strSql.Append("cr_oid=" + model.cr_oid + ",");
            }
            else
            {
                strSql.Append("cr_oid= null ,");
            }
            if (model.cr_pid != null)
            {
                strSql.Append("cr_pid=" + model.cr_pid + ",");
            }
            else
            {
                strSql.Append("cr_pid= null ,");
            }
            if (model.cr_time != null)
            {
                strSql.Append("cr_time='" + model.cr_time + "',");
            }
            else
            {
                strSql.Append("cr_time= null ,");
            }
            if (model.cr_type != null)
            {
                strSql.Append("cr_type=" + model.cr_type + ",");
            }
            else
            {
                strSql.Append("cr_type= null ,");
            }
            if (model.cr_num != null)
            {
                strSql.Append("cr_num=" + model.cr_num + ",");
            }
            else
            {
                strSql.Append("cr_num= null ,");
            }
            if (model.cr_yan != null)
            {
                strSql.Append("cr_yan=" + model.cr_yan + ",");
            }
            else
            {
                strSql.Append("cr_yan= null ,");
            }
            if (model.cr_price != null)
            {
                strSql.Append("cr_price=" + model.cr_price + ",");
            }
            else
            {
                strSql.Append("cr_price= null ,");
            }
            if (model.cr_remark != null)
            {
                strSql.Append("cr_remark='" + model.cr_remark + "',");
            }
            else
            {
                strSql.Append("cr_remark= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where cr_id=" + model.cr_id + "");
            int rowsAffected = DbSQL.ExecuteSql(strSql.ToString());

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #6
0
        private void tbBtnClick(object sender, ToolBarButtonClickEventArgs e)
        {
            if (e.Button.ToolTipText == "新增")
            {
                rstValue();
                setModifyMode(true);
                optrowid = null;
            }
            if (e.Button.ToolTipText == "修改")
            {
                if (!String.IsNullOrEmpty(optrowid))
                {
                    setModifyMode(true);
                }
                else
                {
                    MessageBox.Show("请选择所要修改的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            if (e.Button.ToolTipText == "删除")
            {
                if (!String.IsNullOrEmpty(optrowid))
                {
                    DialogResult result = MessageBox.Show("确认删除?", "删除数据", MessageBoxButtons.OKCancel);
                    if (result == DialogResult.OK)
                    {
                        dal.Delete(int.Parse(optrowid));
                        rstValue();
                        MessageBox.Show("恭喜你,删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        bindData("cr_type=3");
                        setModifyMode(false);
                        optrowid = null;
                    }
                }
                else
                {
                    MessageBox.Show("请选择所要删除的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            if (e.Button.ToolTipText == "提交")
            {
                if (validateInput())
                {
                    model = new Model.tb_churu();
                    if (!string.IsNullOrEmpty(optrowid))
                    {
                        model = dal.GetModel(int.Parse(optrowid));
                    }
                    model.cr_pid    = int.Parse(txttyid.Text);
                    model.cr_remark = txtdesc.Text;
                    model.cr_type   = 3;
                    int tempNum = int.Parse(this.txtnum.Text);
                    if (tempNum <= 0)
                    {
                        MessageBox.Show("输入数量有误,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    model.cr_num = tempNum;
                    if (String.IsNullOrEmpty(optrowid))
                    {
                        model.cr_time = System.DateTime.Now.ToString("yyyy-MM-dd");
                        Model.tb_proc mop = new Model.tb_proc();
                        BLL.tb_proc   dap = new BLL.tb_proc();
                        mop = dap.GetModel(int.Parse(txttyid.Text));
                        if (mop.p_num < int.Parse(this.txtnum.Text))
                        {
                            MessageBox.Show("库存不足,请更换", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(mop.p_xx))
                            {
                                if (mop.p_num < int.Parse(mop.p_xx))
                                {
                                    MessageBox.Show("已达到库存预警下限", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                            }
                            if (dal.Add(model) > 0)
                            {
                                mop.p_num = mop.p_num - int.Parse(this.txtnum.Text);
                                dap.Update(mop);
                                MessageBox.Show("恭喜你,报废成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                rstValue();
                                bindData("cr_type=3");
                                setModifyMode(false);
                                optrowid = null;
                            }
                        }
                    }
                    else
                    {
                        if (dal.Update(model))
                        {
                            MessageBox.Show("恭喜你,修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            rstValue();
                            bindData("cr_type=3");
                            setModifyMode(false);
                            optrowid = null;
                        }
                    }
                }
            }

            if (e.Button.ToolTipText == "取消")
            {
                bindData("cr_type=3");
                rstValue();
                setModifyMode(false);
                optrowid = null;
            }

            if (e.Button.ToolTipText == "退出")
            {
                this.Close();
            }
        }