Пример #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(VAN_OA.Model.EFrom.Tb_ExpInvs model, SqlCommand objCommand)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.PId != null)
            {
                strSql1.Append("PId,");
                strSql2.Append("" + model.PId + ",");
            }
            if (model.InvId != null)
            {
                strSql1.Append("InvId,");
                strSql2.Append("" + model.InvId + ",");
            }
            if (model.ExpNum != null)
            {
                strSql1.Append("ExpNum,");
                strSql2.Append("" + model.ExpNum + ",");
            }
            if (model.ExpUse != null)
            {
                strSql1.Append("ExpUse,");
                strSql2.Append("'" + model.ExpUse + "',");
            }
            if (model.ExpState != null)
            {
                strSql1.Append("ExpState,");
                strSql2.Append("'" + model.ExpState + "',");
            }
            if (model.ExpRemark != null)
            {
                strSql1.Append("ExpRemark,");
                strSql2.Append("'" + model.ExpRemark + "',");
            }
            if (model.ReturnTime != null)
            {
                strSql1.Append("ReturnTime,");
                strSql2.Append("'" + model.ReturnTime + "',");
            }
            strSql.Append("insert into Tb_ExpInvs(");
            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");
            int result;

            objCommand.CommandText = strSql.ToString();
            object obj = objCommand.ExecuteScalar();

            if (!int.TryParse(obj.ToString(), out result))
            {
                return(0);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(VAN_OA.Model.EFrom.Tb_ExpInvs model, SqlCommand objCommand)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tb_ExpInvs set ");
            if (model.PId != null)
            {
                strSql.Append("PId=" + model.PId + ",");
            }
            if (model.InvId != null)
            {
                strSql.Append("InvId=" + model.InvId + ",");
            }
            if (model.ExpNum != null)
            {
                strSql.Append("ExpNum=" + model.ExpNum + ",");
            }
            if (model.ExpUse != null)
            {
                strSql.Append("ExpUse='" + model.ExpUse + "',");
            }
            else
            {
                strSql.Append("ExpUse= null ,");
            }
            if (model.ExpState != null)
            {
                strSql.Append("ExpState='" + model.ExpState + "',");
            }
            else
            {
                strSql.Append("ExpState= null ,");
            }
            if (model.ExpRemark != null)
            {
                strSql.Append("ExpRemark='" + model.ExpRemark + "',");
            }
            else
            {
                strSql.Append("ExpRemark= null ,");
            }
            if (model.ReturnTime != null)
            {
                strSql.Append("ReturnTime='" + model.ReturnTime + "',");
            }
            else
            {
                strSql.Append("ReturnTime= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where Id=" + model.Id + "");
            objCommand.CommandText = strSql.ToString();
            objCommand.ExecuteNonQuery();
        }
Пример #3
0
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public VAN_OA.Model.EFrom.Tb_ExpInvs ReaderBind(IDataReader dataReader)
        {
            VAN_OA.Model.EFrom.Tb_ExpInvs model = new VAN_OA.Model.EFrom.Tb_ExpInvs();
            object ojb;

            ojb = dataReader["Id"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Id = (int)ojb;
            }
            ojb = dataReader["PId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PId = (int)ojb;
            }
            ojb = dataReader["InvId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.InvId = (int)ojb;
            }
            ojb = dataReader["ExpNum"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ExpNum = (decimal)ojb;
            }
            model.ExpUse    = dataReader["ExpUse"].ToString();
            model.ExpState  = dataReader["ExpState"].ToString();
            model.ExpRemark = dataReader["ExpRemark"].ToString();
            ojb             = dataReader["ReturnTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ReturnTime = (DateTime)ojb;
            }

            ojb = dataReader["InvName"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.InvName = Convert.ToString(ojb);
            }


            ojb = dataReader["InvNo"];
            if (ojb != null && ojb != DBNull.Value && ojb.ToString() != "")
            {
                model.InvName += "---" + ojb.ToString();
            }
            return(model);
        }
Пример #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public VAN_OA.Model.EFrom.Tb_ExpInvs GetModel(int Ids)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select   ");
            strSql.Append(" Tb_ExpInvs.Id,PId,InvId,ExpNum,ExpUse,ExpState,ExpRemark,ReturnTime,InvName");
            strSql.Append(" from Tb_ExpInvs left join Tb_Inventory on Tb_Inventory.Id=Tb_ExpInvs.InvId");
            strSql.Append(" where Tb_ExpInvs.Id=" + Ids + "");
            VAN_OA.Model.EFrom.Tb_ExpInvs model = null;
            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlCommand objCommand = new SqlCommand(strSql.ToString(), conn);
                using (SqlDataReader dataReader = objCommand.ExecuteReader())
                {
                    if (dataReader.Read())
                    {
                        model = ReaderBind(dataReader);
                    }
                }
            }
            return(model);
        }
Пример #5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (ddlInvs.Text.Trim() == "")
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('请选择货品!');</script>");
                ddlInvs.Focus();
                return;
            }


            try
            {
                Convert.ToDecimal(txtExpNum.Text);
            }
            catch (Exception)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('数量格式错误!');</script>");
                txtExpNum.Focus();
                return;
            }

            if (Convert.ToDecimal(txtExpNum.Text) <= 0)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('请填写数量!');</script>");
                txtExpNum.Focus();
                return;
            }


            int     InvId     = int.Parse(ddlInvs.SelectedItem.Value);
            decimal ExpNum    = decimal.Parse(this.txtExpNum.Text);
            string  ExpUse    = this.txtExpUse.Text;
            string  ExpState  = this.ddlExpState.Text;
            string  ExpRemark = this.txtExpRemark.Text;


            VAN_OA.Model.EFrom.Tb_ExpInvs model = new VAN_OA.Model.EFrom.Tb_ExpInvs();

            model.InvId     = InvId;
            model.ExpNum    = ExpNum;
            model.ExpUse    = ExpUse;
            model.ExpState  = ExpState;
            model.ExpRemark = ExpRemark;
            model.InvName   = ddlInvs.SelectedItem.Text;
            if (txtResultRemark.Visible == true && txtReturnTime.Text != "")
            {
                try
                {
                    model.ReturnTime = Convert.ToDateTime(txtReturnTime.Text);
                }
                catch (Exception)
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('归还时间格式有误!');</script>");
                    txtResultRemark.Focus();
                    return;
                }
            }
            else
            {
                model.ReturnTime = null;
            }

            if (ViewState["state"] != null)
            {
                if (ViewState["state"].ToString() == "add")
                {
                    List <Tb_ExpInvs> POOrders = Session["ProInvs"] as List <Tb_ExpInvs>;
                    POOrders.Add(model);
                    Session["ProInvs"] = POOrders;

                    gvList.DataSource = POOrders;
                    gvList.DataBind();

                    ddlInvs.SelectedIndex = -1;
                    txtExpNum.Text        = "0";
                    txtExpRemark.Text     = "";
                    txtExpUse.Text        = "";
                    ddlInvs.Focus();
                    ViewState["state"] = "add";
                    return;
                }
                if (ViewState["state"].ToString() == "edit" && ViewState["index"] != null)
                {
                    int index = Convert.ToInt32(ViewState["index"]);
                    if (Session["ProInvs"] != null)
                    {
                        List <Tb_ExpInvs> POOrders = Session["ProInvs"] as List <Tb_ExpInvs>;

                        Tb_ExpInvs modelPro = POOrders[index];

                        model.Id           = modelPro.Id;
                        model.IfUpdate     = true;
                        POOrders[index]    = model;
                        Session["ProInvs"] = POOrders;

                        gvList.DataSource = POOrders;
                        gvList.DataBind();
                    }
                }
            }

            btnAdd.Enabled    = true;
            btnSave.Enabled   = false;
            btnCancel.Enabled = false;
        }