예제 #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(业务.Model.检验标准档案 model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.发射器ID != null)
            {
                strSql1.Append("发射器ID,");
                strSql2.Append("" + model.发射器ID + ",");
            }
            if (model.量具品名 != null)
            {
                strSql1.Append("量具品名,");
                strSql2.Append("'" + model.量具品名 + "',");
            }
            if (model.测定项目 != null)
            {
                strSql1.Append("测定项目,");
                strSql2.Append("'" + model.测定项目 + "',");
            }
            if (model.规格 != null)
            {
                strSql1.Append("规格,");
                strSql2.Append("'" + model.规格 + "',");
            }
            if (model.测定项目日文 != null)
            {
                strSql1.Append("测定项目日文,");
                strSql2.Append("N'" + model.测定项目日文 + "',");
            }
            if (model.尺寸公差 != null)
            {
                strSql1.Append("尺寸公差,");
                strSql2.Append("'" + model.尺寸公差 + "',");
            }
            if (model.限 != null)
            {
                strSql1.Append("下限,");
                strSql2.Append("" + model.限 + ",");
            }
            if (model.限 != null)
            {
                strSql1.Append("上限,");
                strSql2.Append("" + model.限 + ",");
            }
            if (model.备注 != null)
            {
                strSql1.Append("备注,");
                strSql2.Append("'" + model.备注 + "',");
            }
            strSql.Append("insert into 检验标准档案(");
            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>
        private void btnSave()
        {
            string sErr   = "";
            int    iCount = 0;

            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                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++)
                    {
                        if (!BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColSelected)))
                        {
                            continue;
                        }

                        if (gridView1.GetRowCellValue(i, gridCol发射器ID).ToString().Trim() == "" && gridView1.GetRowCellValue(i, gridCol测定项目).ToString().Trim() == "")
                        {
                            continue;
                        }
                        long lID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiID));

                        Model.检验标准档案 mod = new 业务.Model.检验标准档案();
                        mod.发射器ID = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridCol发射器ID));
                        if (mod.发射器ID == 0)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "发射器ID不正确\n";
                            continue;
                        }

                        mod.量具品名 = gridView1.GetRowCellValue(i, gridCol量具品名).ToString().Trim();
                        if (mod.量具品名 == string.Empty)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "量具品名不正确\n";
                            continue;
                        }

                        mod.测定项目 = gridView1.GetRowCellValue(i, gridCol测定项目).ToString().Trim();
                        if (mod.测定项目 == string.Empty)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "测定项目不正确\n";
                            continue;
                        }


                        mod.测定项目日文 = gridView1.GetRowCellValue(i, gridCol测定项目日文).ToString().Trim();
                        mod.规格     = gridView1.GetRowCellValue(i, gridCol规格).ToString().Trim();

                        mod.尺寸公差 = gridView1.GetRowCellValue(i, gridCol尺寸公差).ToString().Trim();
                        if (mod.尺寸公差 == string.Empty)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "尺寸公差不正确\n";
                            continue;
                        }

                        if (gridView1.GetRowCellValue(i, gridCol下限).ToString().Trim() != "")
                        {
                            mod.限 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol下限));
                        }
                        if (gridView1.GetRowCellValue(i, gridCol上限).ToString().Trim() != "")
                        {
                            mod.限 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol上限));
                        }

                        if (gridView1.GetRowCellValue(i, gridCol下限).ToString().Trim() != "" && gridView1.GetRowCellValue(i, gridCol上限).ToString().Trim() != "" && mod.限 > mod.限)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "上下限数值不正确\n";
                            continue;
                        }

                        if (BaseFunction.ReturnDecimal(mod.限) == 0 && BaseFunction.ReturnDecimal(mod.限) == 0)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "上下限数值不正确\n";
                            continue;
                        }

                        mod.备注  = gridView1.GetRowCellValue(i, gridCol备注).ToString().Trim();
                        mod.iID = lID;

                        DAL.检验标准档案 dal = new 业务.DAL.检验标准档案();

                        if (lID > 0)
                        {
                            sSQL = dal.Update(mod);
                        }
                        else
                        {
                            sSQL = dal.Add(mod);
                        }
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    if (sErr.Length > 0)
                    {
                        throw new Exception(sErr);
                    }

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

                        MessageBox.Show("保存成功");

                        GetGrid();
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception ee)
            {
                throw new Exception(ee.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public string Update(业务.Model.检验标准档案 model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update 检验标准档案 set ");
            if (model.发射器ID != null)
            {
                strSql.Append("发射器ID=" + model.发射器ID + ",");
            }
            else
            {
                strSql.Append("发射器ID= null ,");
            }
            if (model.量具品名 != null)
            {
                strSql.Append("量具品名='" + model.量具品名 + "',");
            }
            else
            {
                strSql.Append("量具品名= null ,");
            }
            if (model.测定项目 != null)
            {
                strSql.Append("测定项目='" + model.测定项目 + "',");
            }
            else
            {
                strSql.Append("测定项目= null ,");
            }


            if (model.规格 != null)
            {
                strSql.Append("规格='" + model.规格 + "',");
            }
            else
            {
                strSql.Append("规格= null ,");
            }
            if (model.测定项目日文 != null)
            {
                strSql.Append("测定项目日文=N'" + model.测定项目日文 + "',");
            }
            else
            {
                strSql.Append("测定项目日文= null ,");
            }
            if (model.尺寸公差 != null)
            {
                strSql.Append("尺寸公差='" + model.尺寸公差 + "',");
            }
            else
            {
                strSql.Append("尺寸公差= null ,");
            }
            if (model.限 != null)
            {
                strSql.Append("下限=" + model.限 + ",");
            }
            else
            {
                strSql.Append("下限= null ,");
            }
            if (model.限 != null)
            {
                strSql.Append("上限=" + model.限 + ",");
            }
            else
            {
                strSql.Append("上限= null ,");
            }
            if (model.备注 != null)
            {
                strSql.Append("备注='" + model.备注 + "',");
            }
            else
            {
                strSql.Append("备注= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where iID=" + model.iID + "");
            return(strSql.ToString());
        }