示例#1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._InvProcessPrice model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.FromWorkCenter != null)
            {
                strSql1.Append("FromWorkCenter,");
                strSql2.Append("'" + model.FromWorkCenter + "',");
            }
            if (model.CaseType != null)
            {
                strSql1.Append("CaseType,");
                strSql2.Append("'" + model.CaseType + "',");
            }
            if (model.Price != null)
            {
                strSql1.Append("Price,");
                strSql2.Append("" + model.Price + ",");
            }
            if (model.Remark != null)
            {
                strSql1.Append("Remark,");
                strSql2.Append("'" + model.Remark + "',");
            }
            if (model.CreateUid != null)
            {
                strSql1.Append("CreateUid,");
                strSql2.Append("'" + model.CreateUid + "',");
            }
            if (model.CreateDate != null)
            {
                strSql1.Append("CreateDate,");
                strSql2.Append("'" + model.CreateDate + "',");
            }
            strSql.Append("insert into _InvProcessPrice(");
            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");
            return(strSql.ToString());
        }
示例#2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._InvProcessPrice model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update _InvProcessPrice set ");

            if (model.Price != null)
            {
                strSql.Append("Price=" + model.Price + ",");
            }
            if (model.Remark != null)
            {
                strSql.Append("Remark='" + model.Remark + "',");
            }
            else
            {
                strSql.Append("Remark= null ,");
            }
            if (model.CreateUid != null)
            {
                strSql.Append("CreateUid='" + model.CreateUid + "',");
            }
            else
            {
                strSql.Append("CreateUid= null ,");
            }
            if (model.CreateDate != null)
            {
                strSql.Append("CreateDate='" + model.CreateDate + "',");
            }
            else
            {
                strSql.Append("CreateDate= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where FromWorkCenter='" + model.FromWorkCenter + "' and CaseType='" + model.CaseType + "'");
            return(strSql.ToString());
        }
示例#3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string sErr   = "";
            int    iCount = 0;

            try
            {
                gridView1.PostEditor();

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string   sSQL     = "select getdate()";
                    DateTime dNow     = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd"));

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        int    iID    = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColiID));
                        string iState = gridView1.GetRowCellValue(i, gridColiState).ToString().Trim();

                        if (iState == "")
                        {
                            continue;
                        }

                        if (gridView1.GetRowCellValue(i, gridColFromWorkCenter).ToString().Trim() == "")
                        {
                            continue;
                        }

                        Model._InvProcessPrice model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._InvProcessPrice();
                        decimal dPrice = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPrice));
                        if (dPrice <= 0)
                        {
                            sErr = sErr + "Row " + (i + 1).ToString() + " Please set price\n";
                            continue;
                        }
                        model.Price          = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPrice));
                        model.FromWorkCenter = gridView1.GetRowCellValue(i, gridColFromWorkCenter).ToString().Trim();
                        model.CaseType       = gridView1.GetRowCellValue(i, gridColCaseType).ToString().Trim();
                        model.Remark         = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim();

                        if (iID == 0)
                        {
                            model.CreateUid  = sUserID;
                            model.CreateDate = dNowDate;

                            DAL._InvProcessPrice dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._InvProcessPrice();
                            sSQL   = dal.Add(model);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        else
                        {
                            model.CreateUid  = gridView1.GetRowCellValue(i, gridColCreateUid).ToString().Trim();
                            model.CreateDate = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColCreateDate));
                            DAL._InvProcessPrice dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._InvProcessPrice();
                            sSQL   = dal.Update(model);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }

                    if (sErr != "")
                    {
                        throw new Exception(sErr);
                    }

                    if (iCount > 0)
                    {
                        tran.Commit();

                        MessageBox.Show("OK");

                        GetGrid();
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }