Ejemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(Base.Model.Inventory_History model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.cInvCode != null)
            {
                strSql1.Append("cInvCode,");
                strSql2.Append("'" + model.cInvCode + "',");
            }
            if (model.cInvNameOld != null)
            {
                strSql1.Append("cInvNameOld,");
                strSql2.Append("'" + model.cInvNameOld + "',");
            }
            if (model.cInvStdOld != null)
            {
                strSql1.Append("cInvStdOld,");
                strSql2.Append("'" + model.cInvStdOld + "',");
            }
            if (model.cInvNameNew != null)
            {
                strSql1.Append("cInvNameNew,");
                strSql2.Append("'" + model.cInvNameNew + "',");
            }
            if (model.cInvStdNew != null)
            {
                strSql1.Append("cInvStdNew,");
                strSql2.Append("'" + model.cInvStdNew + "',");
            }
            if (model.CreateUid != null)
            {
                strSql1.Append("CreateUid,");
                strSql2.Append("'" + model.CreateUid + "',");
            }
            if (model.dtmCreate != null)
            {
                strSql1.Append("dtmCreate,");
                strSql2.Append("getdate(),");
            }
            strSql.Append("insert into @u8.Inventory_History(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return(strSql.ToString());
        }
Ejemplo n.º 2
0
        private void btnSave()
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }
                ArrayList aList = new ArrayList();
                string    sErr  = "";

                SqlConnection conn = new SqlConnection(FrameBaseFunction.ClsBaseDataInfo.sConnString2);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();

                try
                {
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        string sInvCode = gridView1.GetRowCellValue(i, gridCol存货编码).ToString().Trim();
                        string sInvName = gridView1.GetRowCellValue(i, gridCol存货名称).ToString().Trim();
                        string sInvStd  = gridView1.GetRowCellValue(i, gridCol规格型号).ToString().Trim();

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

                        if (sInvName == "")
                        {
                            sErr = sErr + "行 " + (i + 1).ToString().Trim() + " 存货名称不能为空\n";
                        }

                        sSQL = @"
select * from @u8.Inventory where cInvCode = '{0}'
";
                        sSQL = string.Format(sSQL, sInvCode);
                        DataTable dtTemp = ClsSqlHelper.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtTemp != null && dtTemp.Rows.Count > 0 && dtTemp.Rows[0][0].ToString().Trim() == sInvCode)
                        {
                            Model.Inventory_History mod = new Base.Model.Inventory_History();
                            mod.cInvCode    = sInvCode;
                            mod.cInvNameOld = dtTemp.Rows[0]["cInvName"].ToString().Trim();
                            mod.cInvStdOld  = dtTemp.Rows[0]["cInvStd"].ToString().Trim();
                            mod.cInvNameNew = sInvName;
                            mod.cInvStdNew  = sInvStd;
                            mod.CreateUid   = sUserName;

                            DAL.Inventory_History dal = new Base.DAL.Inventory_History();
                            sSQL = dal.Add(mod);
                            sSQL = sSQL.Replace("@u8", FrameBaseFunction.ClsBaseDataInfo.sUFDataBaseName.Trim() + ".dbo");

                            ClsSqlHelper.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            sSQL = @"
update @u8.Inventory set cInvName = '{0}' ,cInvStd = '{1}' where cInvCode = '{2}'
";
                            sSQL = string.Format(sSQL, sInvName, sInvStd, sInvCode);
                            sSQL = sSQL.Replace("@u8", FrameBaseFunction.ClsBaseDataInfo.sUFDataBaseName.Trim() + ".dbo");

                            ClsSqlHelper.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        else
                        {
                            sErr = sErr + "行 " + (i + 1).ToString().Trim() + " 存货编码不存在\n";
                        }
                    }

                    if (sErr.Length > 0)
                    {
                        throw new Exception(sErr);
                    }
                    else
                    {
                        tran.Commit();
                        MessageBox.Show("保存成功!");

                        gridControl1.DataSource = null;
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();

                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                throw new Exception(ee.Message);
            }
        }