예제 #1
0
        //插入单个
        public int Insert(ref M_Invoice Obj, ref string ErrMsg)
        {
            SqlConnection conn;
            using (conn = CreatConn())
            {
                SqlCommand cmd = new SqlCommand($"insert into {TableName} (Purchase_ID,InvoiceTime,InvoicePrice,InvoiceNumber,InvoiceCompanyName,BankNumber,Remark) values (@Purchase_ID,@InvoiceTime,@InvoicePrice,@InvoiceNumber,@InvoiceCompanyName,@BankNumber,@Remark);select @@IDENTITY as int", conn);

                SqlParameter par = new SqlParameter("@Purchase_ID", SqlDbType.Int);
                par.Value = Obj.Purchase_ID;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@InvoiceTime", SqlDbType.DateTime);
                par.Value = Obj.InvoiceTime;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@InvoicePrice", SqlDbType.Float);
                par.Value = Obj.InvoicePrice;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@InvoiceNumber", SqlDbType.Char, 10);
                par.Value = Obj.InvoiceNumber;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@InvoiceCompanyName", SqlDbType.Char, 100);
                if (Obj.InvoiceCompanyName == null) { par.Value = DBNull.Value; } else { par.Value = Obj.InvoiceCompanyName; }
                cmd.Parameters.Add(par);

                par = new SqlParameter("@BankNumber", SqlDbType.Char, 50);
                par.Value = Obj.BankNumber;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@Remark", SqlDbType.Char, 100);
                par.Value = Obj.Remark;
                cmd.Parameters.Add(par);

                try
                {
                    conn.Open();
                    decimal d = (decimal)cmd.ExecuteScalar();
                    Obj.ID = (int)d;
                    if (Obj.ID > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                catch (Exception ex)
                {
                    ErrMsg = ex.Message;
                    return -1;
                }
                finally
                {
                    cmd.Dispose();
                }
            }
        }
예제 #2
0
        //查询多个(查ID)
        public int Select(ref List<M_Invoice> Obj, List<int> ID, ref string ErrMsg)
        {
            SqlConnection conn;
            using (conn = CreatConn())
            {
                SqlCommand cmd = new SqlCommand($"select ID,Purchase_ID,InvoiceTime,InvoicePrice,InvoiceNumber,InvoiceCompanyName,BankNumber,Remark from {TableName} where ID = @ID", conn);
                SqlDataReader sdr;
                SqlParameter par = new SqlParameter("@ID", SqlDbType.Int);
                cmd.Parameters.Add(par);

                int tmpOut = 0;
                try
                {
                    conn.Open();
                    foreach (int i in ID)
                    {
                        cmd.Parameters["@ID"].Value = i;
                        sdr = cmd.ExecuteReader();
                        while (sdr.Read())
                        {
                            M_Invoice TmpObj = new M_Invoice();
                            TmpObj.ID = (int)sdr["ID"];
                            TmpObj.BankNumber = (string)sdr["BankNumber"];
                            if (sdr["InvoiceCompanyName"] == DBNull.Value) { TmpObj.InvoiceCompanyName = string.Empty; } else { TmpObj.InvoiceCompanyName = (string)sdr["InvoiceCompanyName"]; }
                            TmpObj.InvoiceNumber = (string)sdr["InvoiceNumber"];
                            TmpObj.InvoicePrice = (int)sdr["InvoicePrice"];
                            TmpObj.InvoiceTime = (DateTime)sdr["InvoiceTime"];
                            TmpObj.Purchase_ID = (int)sdr["Purchase_ID"];
                            TmpObj.Remark = (string)sdr["Remark"];
                            Obj.Add(TmpObj);
                            tmpOut++;
                        }
                        sdr.Close();
                    }
                }
                catch (Exception ex)
                {
                    ErrMsg = ex.Message;
                    return -1;
                }
                finally
                {
                    cmd.Dispose();
                }
                if (ID.Count() == tmpOut)
                {
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
        }
예제 #3
0
 //查询单个(查ID)
 public int Select(ref M_Invoice Obj, int ID, ref string ErrMsg)
 {
     SqlConnection conn;
     using (conn = CreatConn())
     {
         SqlCommand cmd = new SqlCommand($"select ID,Purchase_ID,InvoiceTime,InvoicePrice,InvoiceNumber,InvoiceCompanyName,BankNumber,Remark from {TableName} where ID = {ID}", conn);
         SqlDataReader sdr;
         try
         {
             conn.Open();
             sdr = cmd.ExecuteReader();
             while (sdr.Read())
             {
                 Obj.ID = (int)sdr["ID"];
                 Obj.BankNumber = (string)sdr["BankNumber"];
                 if (sdr["InvoiceCompanyName"] == DBNull.Value) { Obj.InvoiceCompanyName = string.Empty; } else { Obj.InvoiceCompanyName = (string)sdr["InvoiceCompanyName"]; }
                 Obj.InvoiceNumber = (string)sdr["InvoiceNumber"];
                 Obj.InvoicePrice = (float)sdr["InvoicePrice"];
                 Obj.InvoiceTime = (DateTime)sdr["InvoiceTime"];
                 Obj.Purchase_ID = (int)sdr["Purchase_ID"];
                 Obj.Remark = (string)sdr["Remark"];
                 return 1;
             }
             return -1;
         }
         catch (Exception ex)
         {
             ErrMsg = ex.Message;
             return -1;
         }
         finally
         {
             cmd.Dispose();
         }
     }
 }
예제 #4
0
        //更新单个(查ID)
        public int Update(M_Invoice Obj, ref string ErrMsg)
        {
            SqlConnection conn;
            using (conn = CreatConn())
            {
                SqlCommand cmd = new SqlCommand($"update {TableName} set Purchase_ID = @Purchase_ID, InvoiceTime = @InvoiceTime, InvoicePrice = @InvoicePrice, InvoiceNumber = @InvoiceNumber, InvoiceCompanyName = @InvoiceCompanyName, BankNumber = @BankNumber, Remark = @Remark where ID = @ID", conn);

                SqlParameter par = new SqlParameter("@Purchase_ID", SqlDbType.Int);
                par.Value = Obj.Purchase_ID;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@InvoiceTime", SqlDbType.DateTime);
                par.Value = Obj.InvoiceTime;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@InvoicePrice", SqlDbType.Float);
                par.Value = Obj.InvoicePrice;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@InvoiceNumber", SqlDbType.Char, 10);
                par.Value = Obj.InvoiceNumber;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@InvoiceCompanyName", SqlDbType.Char, 100);
                if (Obj.InvoiceCompanyName == null) { par.Value = DBNull.Value; } else { par.Value = Obj.InvoiceCompanyName; }
                cmd.Parameters.Add(par);

                par = new SqlParameter("@BankNumber", SqlDbType.Char, 50);
                par.Value = Obj.BankNumber;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@Remark", SqlDbType.Char, 100);
                par.Value = Obj.Remark;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@ID", SqlDbType.Int);
                par.Value = Obj.ID;
                cmd.Parameters.Add(par);

                try
                {
                    conn.Open();
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                catch (Exception ex)
                {
                    ErrMsg = ex.Message;
                    return -1;
                }
                finally
                {
                    cmd.Dispose();
                }
            }
        }
예제 #5
0
 //查询单个(查ID)
 public static int Select(ref M_Invoice Obj, int ID, ref string ErrMsg)
 {
     I_Invoice I = (D_Invoice)SimpleFactory.CreateObject(DBType.Invoice);
     return I.Select(ref Obj, ID, ref ErrMsg);
 }
예제 #6
0
 //更新单个(查ID)
 public static int Update(M_Invoice Obj, ref string ErrMsg)
 {
     I_Invoice I = (D_Invoice)SimpleFactory.CreateObject(DBType.Invoice);
     return I.Update(Obj, ref ErrMsg);
 }