public bool AddSaleBillDetailToDatabase(SaleBillDetail saleBillDetail)
        {
            try
            {
                OpenConnection();
                string     queryString = "Insert Into CHITIETPBH Values(@idSaleBillDetail, @idSaleBill, @idGood, @quantity, @price)";
                SqlCommand command     = new SqlCommand(queryString, conn);
                command.Parameters.AddWithValue("@idSaleBillDetail", saleBillDetail.IdSaleBillDetail);
                command.Parameters.AddWithValue("@idSaleBill", saleBillDetail.IdSaleBill);
                command.Parameters.AddWithValue("@idGood", saleBillDetail.IdGood);
                command.Parameters.AddWithValue("@quantity", saleBillDetail.Quantity);
                command.Parameters.AddWithValue("@price", saleBillDetail.Price);

                int rs = command.ExecuteNonQuery();
                if (rs != 1)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Thêm thất bại!" + e, "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                CloseConnection();
            }
        }
예제 #2
0
 public SaleBillDetailViewModel(SaleBillDetail saleBillDetail)
 {
     this.Id          = saleBillDetail.Id;
     this.SaleBillId  = saleBillDetail.SaleBillId;
     this.ProductId   = saleBillDetail.ProductId;
     this.Price       = saleBillDetail.Price;
     this.Inventory   = saleBillDetail.Product.Inventory;
     this.Quantity    = saleBillDetail.Quantity;
     this.TotalMoney  = saleBillDetail.TotalMoney;
     this.Note        = saleBillDetail.Note;
     this.Serial      = saleBillDetail.Product.Serial;
     this.ProductName = saleBillDetail.Product.ProductName;
 }
예제 #3
0
        public SaleBillDetail MapToSaleBillDetail()
        {
            var result = new SaleBillDetail()
            {
                Id         = this.Id != null ? this.Id : Guid.NewGuid().ToString(),
                SaleBillId = this.SaleBillId,
                ProductId  = this.ProductId,
                Price      = this.Price,
                TotalMoney = this.TotalMoney,
                Quantity   = this.Quantity,
                Note       = this.Note
            };

            return(result);
        }
        public List <SaleBillDetail> ConvertDBToSaleBillDetailList(int idSaleBill)
        {
            DataTable             dt = new DataTable();
            List <SaleBillDetail> saleBillDetails = new List <SaleBillDetail>();

            try
            {
                OpenConnection();
                string queryString = String.Format("Select * from CHITIETPBH Where MaPBH = '{0}'", idSaleBill);

                SqlCommand command = new SqlCommand(queryString, conn);
                command.ExecuteNonQuery();
                SqlDataAdapter adapter = new SqlDataAdapter(command);

                adapter.Fill(dt);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    SaleBillDetail stockCheck = new SaleBillDetail(
                        int.Parse(dt.Rows[i].ItemArray[0].ToString()),
                        int.Parse(dt.Rows[i].ItemArray[1].ToString()),
                        int.Parse(dt.Rows[i].ItemArray[2].ToString()),
                        int.Parse(dt.Rows[i].ItemArray[3].ToString()),
                        long.Parse(dt.Rows[i].ItemArray[4].ToString())
                        );
                    saleBillDetails.Add(stockCheck);
                }
                return(saleBillDetails);
            }
            catch
            {
                return(new List <SaleBillDetail>());
            }
            finally
            {
                CloseConnection();
            }
        }
예제 #5
0
        private static List <SaleBill> ERP_MES_JHD(Hashtable import)
        {
            RFC rfc = new RFC(ConfigurationManager.AppSettings["sapServer"].ToString());
            //RFC rfc = new RFC("SAPTest");
            var lst = new List <SaleBill>();
            //RFC调用函数名
            string funcName = "ZWMS_JHD";
            //传输传给RFC函数的DataSet
            DataSet ids = new DataSet();
            //构建RFC传入表DataTable

            //返回数据的DataSet框架
            DataSet ods = new DataSet();
            //构建Export参数DataTable
            DataTable export = new DataTable();

            export.TableName = "Export";
            export.Columns.Add(new DataColumn("RTYPE", typeof(string))); //消息文本
            export.Columns.Add(new DataColumn("RTMSG", typeof(string))); //消息文本
            ods.Tables.Add(export);
            //构建RFC传出表DataTable
            DataTable odt1 = new DataTable();

            odt1.TableName = "T_HEADER";
            odt1.Columns.Add(new DataColumn("VBELN", typeof(string))); //交货
            odt1.Columns.Add(new DataColumn("VSTEL", typeof(string))); //装运点/接收点
            odt1.Columns.Add(new DataColumn("VKORG", typeof(string))); //销售机构
            odt1.Columns.Add(new DataColumn("LFART", typeof(string))); //交货类型
            //odt1.Columns.Add(new DataColumn("KOKRS", typeof(string)));//客户编号
            odt1.Columns.Add(new DataColumn("WADAT", typeof(string))); //计划货物移动日期
            odt1.Columns.Add(new DataColumn("LFDAT", typeof(string))); //交货日期
            odt1.Columns.Add(new DataColumn("WBSTK", typeof(string))); //货物移动状态总计
            ods.Tables.Add(odt1);


            DataTable odt2 = new DataTable();

            odt2.TableName = "T_ITEM";
            odt2.Columns.Add(new DataColumn("VBELN", typeof(string))); //交货
            odt2.Columns.Add(new DataColumn("POSNR", typeof(string))); //交货项目
            odt2.Columns.Add(new DataColumn("PSTYV", typeof(string))); //交货项目类别
            odt2.Columns.Add(new DataColumn("WERKS", typeof(string))); //工厂
            odt2.Columns.Add(new DataColumn("MATNR", typeof(string))); //物料号
            odt2.Columns.Add(new DataColumn("LGORT", typeof(string))); //库存地点

            odt2.Columns.Add(new DataColumn("CHARG", typeof(string))); //批号
            odt2.Columns.Add(new DataColumn("LICHN", typeof(string))); //供应商的批次
            odt2.Columns.Add(new DataColumn("KDMAT", typeof(string))); //客户物料
            odt2.Columns.Add(new DataColumn("PRODH", typeof(string))); //产品层次
            odt2.Columns.Add(new DataColumn("LFIMG", typeof(string))); //实际已交货量(按销售单位)
            odt2.Columns.Add(new DataColumn("VRKME", typeof(string))); //销售单位

            ods.Tables.Add(odt2);

            //执行RFC函数
            bool ret = rfc.DownloadByRFC(funcName, import, ids, ref ods);

            //根据RFC执行后返回的数据处理业务逻辑
            //DataTable dt = ods.Tables["T_ITEM"];
            foreach (DataRow h in ods.Tables["T_HEADER"].Rows)
            {
                var bill = new SaleBill();
                try
                {
                    string type  = h["LFART"].ToString();
                    string state = h["WBSTK"].ToString();

                    bill.No       = h["VBELN"].ToString();
                    bill.BillDate = DateTime.Now;
                    bill.Location = h["VSTEL"].ToString();
                    bill.Org      = h["VKORG"].ToString();
                    //bill.Location = h["LFART"].ToString();
                    DateTime planDate, deliveryDate;
                    if (DateTime.TryParse(h["WADAT"].ToString(), out planDate))
                    {
                        bill.PlanDate = Convert.ToDateTime(h["WADAT"].ToString());
                    }
                    //else
                    //    bill.PlanDate = Convert.ToDateTime(h["WADAT"].ToString());

                    if (DateTime.TryParse(h["LFDAT"].ToString(), out deliveryDate))
                    {
                        bill.DeliveryDate = Convert.ToDateTime(h["LFDAT"].ToString());
                    }
                    //bill.State = h["WBSTK"].ToString();

                    foreach (DataRow i in ods.Tables["T_ITEM"].AsEnumerable().Where(p => h["VBELN"].ToString() == p["VBELN"].ToString()))
                    {
                        var billDtl = new SaleBillDetail()
                        {
                            Item = new Item {
                                Code = i["MATNR"].ToString()
                            },
                            ProjectNo    = i["POSNR"].ToString(),
                            Qty          = Convert.ToDouble(i["LFIMG"] ?? 0),
                            Unit         = i["VRKME"].ToString(),
                            Factory      = i["WERKS"].ToString(),
                            BatchNo      = i["CHARG"].ToString(),
                            LotNo        = i["LICHN"].ToString(),
                            Warehouse    = i["LGORT"].ToString(),
                            BillType     = i["PSTYV"].ToString(),
                            ProductLevel = i["PRODH"].ToString(),
                        };
                        bill.SaleBillDetailList.Add(billDtl);
                    }
                    lst.Add(bill);
                }
                catch (Exception e)
                {
                    continue;
                }
            }
            return(lst);
        }