Esempio n. 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._RoutingInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update _RoutingInfo set ");
            if (model.RoutingForm != null)
            {
                strSql.Append("RoutingForm='" + model.RoutingForm + "',");
            }
            else
            {
                strSql.Append("RoutingForm= null ,");
            }
            if (model.RoutingTo != null)
            {
                strSql.Append("RoutingTo='" + model.RoutingTo + "',");
            }
            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 RoutingID='" + model.RoutingID + "'");
            return(strSql.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._RoutingInfo model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.RoutingID != null)
            {
                strSql1.Append("RoutingID,");
                strSql2.Append("'" + model.RoutingID + "',");
            }
            if (model.RoutingForm != null)
            {
                strSql1.Append("RoutingForm,");
                strSql2.Append("'" + model.RoutingForm + "',");
            }
            if (model.RoutingTo != null)
            {
                strSql1.Append("RoutingTo,");
                strSql2.Append("'" + model.RoutingTo + "',");
            }
            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 _RoutingInfo(");
            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());
        }
Esempio n. 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string sErr   = "";
            int    iCount = 0;

            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }


                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, gridColRoutingID).ToString().Trim() == "")
                        {
                            continue;
                        }

                        Model._RoutingInfo model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._RoutingInfo();

                        model.RoutingID = gridView1.GetRowCellValue(i, gridColRoutingID).ToString().Trim();

                        model.RoutingForm = gridView1.GetRowCellValue(i, gridColRoutingForm).ToString().Trim();
                        if (model.RoutingForm.Trim() == "")
                        {
                            sErr = sErr + "Row " + (i + 1).ToString() + " Please set RoutingForm \n";
                            continue;
                        }

                        model.RoutingTo = gridView1.GetRowCellValue(i, gridColRoutingTo).ToString().Trim();
                        if (model.RoutingTo.Trim() == "")
                        {
                            sErr = sErr + "Row " + (i + 1).ToString() + " Please set RoutingTo \n";
                            continue;
                        }


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

                            DAL._RoutingInfo dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._RoutingInfo();
                            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._RoutingInfo dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._RoutingInfo();
                            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);
            }
        }