Esempio n. 1
0
        private void GetBoxData(string connStr, ControlVoucher voucher)
        {
            string sql = "";

            if (!isChecked)
            {
                sql = $"select * from crd_credential where `no`='{voucher.VoucherNo}' and `state`={voucher.Status} and personNo='{voucher.PersonNo}'";
            }
            else
            {
                sql = $"select * from crd_credential where `no`='{voucher.VoucherNo}' and `state`={voucher.Status}";
            }

            using (MySqlDataReader reader = MySqlHelper.ExecuteReader(connStr, sql))
            {
                if (!reader.Read())
                {
                    ShowMessage($"凭证[{voucher.VoucherNo}]与中心不一致");
                    if (!isChecked)
                    {
                        RepairData(connStr, voucher);
                    }
                    else
                    {
                        //如果集合中已经存在 就不添加了
                        if (controlVouchers.FindIndex(x => x.VoucherNo == voucher.VoucherNo) < 0)
                        {
                            controlVouchers.Add(voucher);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 private void Compare(ControlVoucher voucher)
 {
     foreach (var ip in dictBoxConnStr.Keys)
     {
         ShowMessage($"比对盒子{ip}的数据");
         GetBoxData(dictBoxConnStr[ip], voucher);
     }
 }
Esempio n. 3
0
        private void RepairData(string connStr, ControlVoucher voucher)
        {
            List <string> devices = new List <string>();
            string        sql     = "select deviceid from crd_device where parentdeviceid=0";
            DataTable     dt      = MySqlHelper.ExecuteDataset(connStr, sql).Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                devices.Add(dr["deviceid"].ToString());
            }
            string deviceList = "";

            devices.ForEach((x) =>
            {
                int index = voucher.DeviceList.FindIndex(m => m == x);
                if (index >= 0)
                {
                    deviceList += x + ";";
                }
            });

            sql = $"select * from crd_credential where `no`='{voucher.VoucherNo}' and `state`={voucher.Status}";
            using (MySqlDataReader reader = MySqlHelper.ExecuteReader(connStr, sql))
            {
                if (reader.Read())
                {
                    string personNo = reader["personNo"].ToString();
                    if (personNo != voucher.PersonNo)
                    {
                        string cmd    = $"update crd_credential set personNo='{voucher.PersonNo}',deviceidList='{deviceList.TrimEnd(';')}' where `no`='{voucher.VoucherNo}' and `state`={voucher.Status} ";
                        int    result = MySqlHelper.ExecuteNonQuery(connStr, cmd);
                        ShowMessage($"更新凭证[{voucher.VoucherNo}]的人事No为[{voucher.PersonNo}],权限列表为[{deviceList}]");
                    }
                }
                else
                {
                    //如果集合中已经存在 就不添加了
                    if (controlVouchers.FindIndex(x => x.VoucherNo == voucher.VoucherNo) < 0)
                    {
                        controlVouchers.Add(voucher);
                    }
                }
            }
        }
        // POST api/PurchaseBillPayment
        public HttpResponseMessage PostPurchaseBillPayment(PurchaseBillPayment purchasebillpayment)
        {
            if (ModelState.IsValid)
            {
                ControlVoucher controlvoucher = new ControlVoucher();
                long SupplierCOAID = (long)db.Collaborators.Where(c => c.CollaboratorID == purchasebillpayment.SupplierID).Select(c => c.SupplierCOAID).FirstOrDefault();
                purchasebillpayment.VoucherNO = controlvoucher.CreateVoucher( SupplierCOAID,(long)purchasebillpayment.CreditTo, (decimal)purchasebillpayment.PaymentTotal, (long)1, (DateTime)purchasebillpayment.Date);
                purchasebillpayment.InsertBy = loginUser.UserID;

                db.PurchaseBillPayments.Add(purchasebillpayment);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, purchasebillpayment);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = purchasebillpayment.PurchaseBillPaymentID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Esempio n. 5
0
        private void CheckVoucher()
        {
            try
            {
                string    cmd       = "select * from control_voucher";
                DataTable dataTable = MySqlHelper.ExecuteDataset(EnvironmentInfo.ConnectionString, cmd).Tables[0];

                foreach (DataRow dr in dataTable.Rows)
                {
                    ControlVoucher voucher = new ControlVoucher();
                    voucher.VGUID = dr["guid"].ToString();
                    voucher.PGUID = dr["pguid"].ToString();
                    //voucher.LGUID = dr["lguid"].ToString();
                    voucher.PersonNo    = dr["personno"].ToString();
                    voucher.VoucherType = int.Parse(dr["vouchertype"].ToString());
                    voucher.VoucherNo   = dr["voucherno"].ToString();
                    voucher.CardNum     = dr["cardnum"].ToString();
                    voucher.Status      = int.Parse(dr["Status"].ToString());
                    voucher.DeviceList  = new List <string>();
                    if (!isChecked)
                    {
                        string    sql   = $"select * from control_voucher_device where VGuid='{voucher.VGUID}'";
                        DataTable table = MySqlHelper.ExecuteDataset(EnvironmentInfo.ConnectionString, sql).Tables[0];
                        foreach (DataRow row in table.Rows)
                        {
                            voucher.DeviceList.Add(row["DeviceId"].ToString());
                        }
                    }
                    Compare(voucher);
                }

                OutPut(null);
                canExecute = true;
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
        }
Esempio n. 6
0
        // POST api/PurchaseBill
        public HttpResponseMessage PostPurchaseBill(PurchaseBill purchasebill)
        {
            if (ModelState.IsValid)
            {
                ControlVoucher controlvoucher = new ControlVoucher();

                //var PurchaseOrder = db.PurchaseOrders.Where(o => o.PurchaseOrderID == purchasebill.PurchaseOrderID).SingleOrDefault();
                //long PurchaseCOAID =(long) PurchaseOrder.PurchaseOrderCategory.COAID;

                //long SupplierCOAID = (long)db.Collaborators.Where(c => c.CollaboratorID == PurchaseOrder.SupplierID).Select(c => c.SupplierCOAID).FirstOrDefault();

                //purchasebill.VoucherNO = controlvoucher.CreateVoucher(PurchaseCOAID, SupplierCOAID, (decimal)purchasebill.GrandTotal, (long)1, (DateTime)purchasebill.Date);
                string CustomCode = "PB-" + DateTime.Now.ToString("yyyyMMdd");

                int? MaxCode = Convert.ToInt32((db.PurchaseBills.Where(r => r.PurchaseBillCode.StartsWith(CustomCode)).Select(r => r.PurchaseBillCode.Substring(CustomCode.Length, 4)).ToList()).Max());
                string PBCode = CustomCode + ((MaxCode + 1).ToString()).PadLeft(4, '0');
                purchasebill.PurchaseBillCode = PBCode;

                purchasebill.InsertBy = loginUser.UserID;

                db.PurchaseBills.Add(purchasebill);
                db.SaveChanges();
                if(purchasebill.PurchaseDeliveryReceiveID>0)
                {
                    PurchaseDeliveryReceive purchasedeliveryreceive = db.PurchaseDeliveryReceives.Where(r => r.PurchaseDeliveryReceiveID == purchasebill.PurchaseDeliveryReceiveID).SingleOrDefault();
                    purchasedeliveryreceive.IsBilled = true;
                    db.Entry(purchasedeliveryreceive).State = EntityState.Modified;
                    db.SaveChanges();
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, purchasebill);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = purchasebill.PurchaseBillID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Esempio n. 7
0
        // POST api/SalesBill
        public HttpResponseMessage PostSalesBill(SalesBill salesbill)
        {
            if (ModelState.IsValid)
            {

                FiscalYear fiscalYear = db.FiscalYears.Where(f => (EntityFunctions.TruncateTime(f.StartDate) <= DateTime.Now) && (EntityFunctions.TruncateTime(f.EndDate) >= DateTime.Now)).SingleOrDefault();
                SalesBillCategory salesBillCategory = db.SalesBillCategories.Where(sb => sb.SalesBillCategoryID == salesbill.SalesBillCategoryID).SingleOrDefault();
                Collaborator custormer = db.Collaborators.Where(c => c.CollaboratorID == salesbill.CustomerID).Include(c => c.CustomerType).SingleOrDefault();

                string CustomCode = salesBillCategory.SalesBillCategoryCode + "/" + custormer.CustomerType.CustomerTypeID.ToString().PadLeft(3, '0') + "/" + fiscalYear.FiscalYearName + "/" + custormer.CollaboratorCode + "-";

                //string CustomCode = "SB-" + DateTime.Now.ToString("yyyyMMdd");
                ControlVoucher controlvoucher = new ControlVoucher();

                long SalesCOAID =(long)db.AccCOAMappings.Where(a => a.AccCOAConfigID == 18 && a.CompanyID == loginUser.CompanyID).Select(a=>a.AccCOAID).FirstOrDefault();

                long CustomerCOAID = (long)db.Collaborators.Where(c => c.CollaboratorID == salesbill.CustomerID).Select(c => c.CustomerCOAID).FirstOrDefault();
                salesbill.VoucherNO = controlvoucher.CreateVoucher(CustomerCOAID, SalesCOAID, (decimal)salesbill.GrandTotal, (long)1, (DateTime)salesbill.Date);

                int? MaxCode = Convert.ToInt32((db.SalesBills.Where(r => r.SalesBillCode.StartsWith(CustomCode)).Select(r => r.SalesBillCode.Substring(CustomCode.Length, 8)).ToList()).Max());
                string SBCode = CustomCode + ((MaxCode + 1).ToString()).PadLeft(8, '0');
                salesbill.SalesBillCode = SBCode;
                salesbill.Date = DateTime.Now.ToLocalTime();
                salesbill.InsertBy = loginUser.UserID;

                db.SalesBills.Add(salesbill);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, salesbill);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = salesbill.SalesBillID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
        // POST api/SalesReceivePayment
        public HttpResponseMessage PostSalesReceivePayment(SalesReceivePayment salesreceivepayment)
        {
            if (ModelState.IsValid)
            {
                ControlVoucher controlvoucher = new ControlVoucher();
                string CustomCode = "SP-" + DateTime.Now.ToString("yyyyMMdd");
                long CustomerCOAID =(long) db.Collaborators.Where(c => c.CollaboratorID == salesreceivepayment.CustomerID).Select(c => c.CustomerCOAID).FirstOrDefault();
                salesreceivepayment.VoucherNO= controlvoucher.CreateVoucher((long)salesreceivepayment.DepositTo, CustomerCOAID, (decimal)salesreceivepayment.PaymentTotal, (long)1, (DateTime)salesreceivepayment.Date);
                int? MaxCode = Convert.ToInt32((db.SalesReceivePayments.Where(r => r.SalesReceivePaymentCode.StartsWith(CustomCode)).Select(r => r.SalesReceivePaymentCode.Substring(CustomCode.Length, 4)).ToList()).Max());
                string SPCode = CustomCode + ((MaxCode + 1).ToString()).PadLeft(4, '0');
                salesreceivepayment.SalesReceivePaymentCode = SPCode;
                salesreceivepayment.Date = DateTime.Now.ToLocalTime();
                db.SalesReceivePayments.Add(salesreceivepayment);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, salesreceivepayment);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = salesreceivepayment.SalesReceivePaymentID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Esempio n. 9
0
        // PUT api/PurchaseBill/5
        public HttpResponseMessage PutPurchaseBill(long id, PurchaseBill purchasebill)
        {
            LoginUser loginUser = new LoginUser();
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != purchasebill.PurchaseBillID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
            if (purchasebill.IsApproved==true)
            {
                long PurchaseCOAID =Convert.ToInt64 (db.AccCOAMappings.Where(a => a.AccCOAConfigID == 22 && a.CompanyID == loginUser.CompanyID).Select(a => a.AccCOAID).SingleOrDefault());
                ControlVoucher controlvoucher = new ControlVoucher();
                var PurchaseOrder = db.PurchaseOrders.Where(o => o.PurchaseOrderID == purchasebill.PurchaseOrderID).SingleOrDefault();
                if(PurchaseOrder!=null)
                {
                    PurchaseCOAID =(long) PurchaseOrder.PurchaseOrderCategory.COAID;
                }

                long SupplierCOAID = (long)db.Collaborators.Where(c => c.CollaboratorID == purchasebill.SupplierID).Select(c => c.SupplierCOAID).FirstOrDefault();

                purchasebill.VoucherNO = controlvoucher.CreateVoucher(PurchaseCOAID, SupplierCOAID, (decimal)purchasebill.GrandTotalApproved, (long)1, (DateTime)purchasebill.Date);

            }

            purchasebill.UpdateBy = loginUser.UserID;

            db.Entry(purchasebill).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }