void hidePanels() { if (PAddRays.Visible) { PAddRays.Hide(); } if (PHistory.Visible) { PHistory.Hide(); } //if (PMedicine.Visible) PMedicine.Hide(); if (pcomment.Visible) { pcomment.Hide(); } if (PAnalysis.Visible) { PAnalysis.Hide(); } }
private void dataGridView1_SelectionChanged(object sender, EventArgs e) { if (dataGridView1.SelectedCells.Count == 0 || dataGridView1.CurrentRow.Cells[0].Value.ToString() == "") { hidePanels(); enableSave(); //btnSave.Enabled = false; } else { unenableSave(); hidePanels(); PHistory.Show(); //load patient info connection.Open(); string s = dataGridView1.CurrentRow.Cells[0].Value.ToString(); cmd = new MySqlCommand("select * from patient,admittion where P_id=A_P_id and A_id=" + s + ";", connection); MySqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { txtID.Text = dr[0].ToString(); txtName.Text = dr[1].ToString(); txtAge.Text = dr[2].ToString(); txtAddress.Text = dr[3].ToString(); txtPhone.Text = dr[4].ToString(); combSex.Text = dr[5].ToString(); combMaritalStatus.Text = dr[6].ToString(); dateRegister.Text = dr[7].ToString(); } if (connection.State == ConnectionState.Open) { connection.Close(); } else { connection.Close(); connection.Open(); } // connection.Close(); //load admittion info //connection.Open(); string id = dataGridView1.CurrentRow.Cells[1].Value.ToString(); da1 = new MySqlDataAdapter("select A_id, A_date from admittion where A_P_id= " + Int32.Parse(id) + ";", connection); dt1.Clear(); da1.Fill(dt1); dataGridView2.DataSource = dt1; if (connection.State == ConnectionState.Open) { connection.Close(); } //load examination info if (connection.State == ConnectionState.Open) { connection.Close(); } else { connection.Close(); connection.Open(); } // connection.Open(); dr.Close(); id = dataGridView1.CurrentRow.Cells[0].Value.ToString(); cmd = new MySqlCommand("select * from examination where E_A_id =" + Int32.Parse(id) + ";", connection); dr = cmd.ExecuteReader(); if (dr.Read()) { txtGeneralLock.Text = dr[2].ToString(); txtPulse.Text = dr[3].ToString(); txtBloodPressure.Text = dr[4].ToString(); txtTemperature.Text = dr[5].ToString(); txtRespiratoryRate.Text = dr[6].ToString(); txtHead.Text = dr[7].ToString(); txtChest.Text = dr[8].ToString(); txtCardiac.Text = dr[9].ToString(); txtInspection.Text = dr[10].ToString(); txtSuperficialPalpation.Text = dr[11].ToString(); txtDeepPalpation.Text = dr[12].ToString(); txtPercussion.Text = dr[13].ToString(); txtAusculation.Text = dr[14].ToString(); txtProvisionalDiagnosis.Text = dr[15].ToString(); } if (connection.State == ConnectionState.Open) { connection.Close(); } } }
// save history protected void saveHistory(string barcode, string caseCode, string boxCode, ProductInfo product, string stt, decimal?quantity, WavehouseInfo wInfo) { var history = new PHistory() { Id = Guid.NewGuid().ToString(), Barcode = barcode, PStatus = stt, BoxCode = boxCode, UserSend = user, WCode = wInfo.wCode, WName = wInfo.wName, WType = wInfo.wType, ProductCode = product.Barcode, CreateDate = DateTime.Now, CaseCode = caseCode, Quantity = quantity }; db.PHistories.Add(history); db.SaveChanges(); var tracking = db.PTrackings.Where(p => p.CaseCode == caseCode && p.WCode == wInfo.wCode).FirstOrDefault(); if (tracking == null) { var pTracking = new PTracking() { Id = Guid.NewGuid().ToString(), WCode = wInfo.wCode, WType = wInfo.wType, WName = wInfo.wName, CaseCode = caseCode, ProductId = product.Id, Quantity = quantity }; if (stt == "NK") { pTracking.ImportTime = DateTime.Now; } else { pTracking.ExportTime = DateTime.Now; } db.PTrackings.Add(pTracking); db.SaveChanges(); } else { if (stt == "NK") { tracking.Quantity = tracking.Quantity + quantity; tracking.ImportTime = DateTime.Now; } else { tracking.Quantity = tracking.Quantity - quantity; tracking.ExportTime = DateTime.Now; } db.Entry(tracking).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public override BarcodeHistory Handle(string barcode) { var caseCode = barcode.Substring(0, 15); var boxCode = ""; BarcodeHistory history = new BarcodeHistory() { Id = Guid.NewGuid().ToString(), CreateTime = DateTime.Now, UserLogin = user, WareHouse = wareActionInfo.wCode, WareHouseType = wareActionInfo.wType, WareHouseName = wareActionInfo.wName, PStatus = "NK", Barcode = barcode, CaseCode = caseCode, IsSuccess = 0 }; var product = GetProduct(barcode); if (product == null) { history.ProductCode = ""; history.ProductName = ""; history.Messenge = "Mã sản phẩm sai"; return(history); } history.ProductName = product.PName; history.ProductCode = product.Barcode; var wareInfo = db.Warehouses.Where(p => p.Code == wareActionInfo.wType).FirstOrDefault(); PHistory checkHistory = null; decimal quantity = 1.0M; if (product.IsBox == 1 && wareInfo.IsScanBox == 1) { boxCode = barcode.Substring(0, 16); // check ma co phai la hop ko var lastChar = barcode.Substring(barcode.Length - 1, 1); if (lastChar != "1") { history.Messenge = "Sản phẩm này chỉ quét hộp"; return(history); } checkHistory = db.PHistories.Where(p => p.BoxCode == boxCode && p.WCode == wareActionInfo.wCode && p.PStatus == "NK").FirstOrDefault(); if (checkHistory != null) { history.Messenge = "Sản phẩm đã xuất kho : " + checkHistory.CreateDate.ToString(); return(history); } quantity = 1.0M / (int)product.QuantityBox; } else { checkHistory = db.PHistories.Where(p => p.CaseCode == caseCode && p.WCode == wareActionInfo.wCode && p.PStatus == "NK").FirstOrDefault(); if (checkHistory != null) { history.Messenge = "Sản phẩm đã nhập kho: " + checkHistory.CreateDate.ToString(); return(history); } } // check kho truoc PHistory checkLastImport = null; if (product.IsBox == 1 && wareInfo.IsScanBox == 1) { checkLastImport = db.PHistories.Where(p => p.CaseCode == caseCode && p.BoxCode == boxCode).OrderByDescending(p => p.CreateDate).FirstOrDefault(); if (checkLastImport == null) { checkLastImport = db.PHistories.Where(p => p.CaseCode == caseCode).OrderByDescending(p => p.CreateDate).FirstOrDefault(); } } else { checkLastImport = db.PHistories.Where(p => p.CaseCode == caseCode).OrderByDescending(p => p.CreateDate).FirstOrDefault(); } if (checkLastImport != null) { // kiem tra do phai kho cha khong var wareLastImport = db.Warehouses.Where(p => p.Code == checkLastImport.WType).FirstOrDefault(); if (!wareLastImport.WareReceive.Contains(wareActionInfo.wType)) { if (wareActionInfo.wType == "CII") { history.Messenge = "Mã đã đại lý cấp 2 khác sử dụng"; } else { history.Messenge = "Mã đã được sử dụng"; } return(history); } if (checkLastImport.PStatus == "NK") { // tru kho saveHistory(barcode, caseCode, boxCode, product, "XK", quantity, new WavehouseInfo() { wCode = checkLastImport.WCode, wName = checkLastImport.WName, wType = checkLastImport.WType }); history.WareRelative = checkLastImport.WCode; history.WareRelativeName = checkLastImport.WName; history.WareRelativeType = checkLastImport.WType; } } else { if (wareActionInfo.wType != "W") { history.Messenge = "Phải nhập kho tổng"; return(history); } } saveHistory(barcode, caseCode, boxCode, product, "NK", quantity, wareActionInfo); history.Quantity = quantity; history.Messenge = "Đã nhập kho"; if (wareActionInfo.wType == "CII") { // neu la cap 2 // kiem tra xem co trong ds barcode k dc tham gia var checkPermiss = db.BarcodeNotPermisses.Where(p => p.CaseCode == caseCode).FirstOrDefault(); if (checkPermiss != null) { history.Messenge = "Đã nhập kho - mã không được tham gia chương trình khuyến mãi"; } } history.IsSuccess = 1; return(history); }
public override BarcodeHistory Handle(string barcode) { var caseCode = barcode.Substring(0, 15); var boxCode = ""; BarcodeHistory history = new BarcodeHistory() { Id = Guid.NewGuid().ToString(), CreateTime = DateTime.Now, UserLogin = user, WareHouse = wareActionInfo.wCode, WareHouseType = wareActionInfo.wType, WareHouseName = wareActionInfo.wName, PStatus = "XK", Barcode = barcode, CaseCode = caseCode, IsSuccess = 0 }; var product = GetProduct(barcode); if (product == null) { history.ProductCode = ""; history.ProductName = ""; history.Messenge = "Mã sản phẩm sai"; return(history); } history.ProductName = product.PName; history.ProductCode = product.Barcode; var wareInfo = db.Warehouses.Where(p => p.Code == wareActionInfo.wType).FirstOrDefault(); PHistory checkHistory = null; decimal quantity = 1.0M; var remain = getInventory(caseCode, wareActionInfo.wCode); if (product.IsBox == 1 && wareInfo.IsScanBox == 1) { boxCode = barcode.Substring(0, 16); // check ma co phai la hop ko var lastChar = barcode.Substring(barcode.Length - 1, 1); if (lastChar != "1") { history.Messenge = "Sản phẩm này chỉ quét hộp"; return(history); } checkHistory = db.PHistories.Where(p => p.BoxCode == boxCode && p.WCode == wareActionInfo.wCode).OrderByDescending(p => p.CreateDate).FirstOrDefault(); quantity = 1.0M / (int)product.QuantityBox; } else { checkHistory = db.PHistories.Where(p => p.CaseCode == caseCode && p.WCode == wareActionInfo.wCode).OrderByDescending(p => p.CreateDate).FirstOrDefault(); } if (checkHistory != null) { if (checkHistory.PStatus == "XK") { history.Messenge = "Sản phẩm đã xuất kho : " + checkHistory.CreateDate.ToString(); return(history); } } else { history.Messenge = "Sản phẩm phải nhập kho"; return(history); } if (remain < quantity) { history.Messenge = "Không đủ hàng để xuất"; return(history); } saveHistory(barcode, caseCode, boxCode, product, "XK", quantity, wareActionInfo); if (wareReceieInfo != null) { saveHistory(barcode, caseCode, boxCode, product, "NK", quantity, wareReceieInfo); history.WareRelative = wareReceieInfo.wCode; history.WareRelativeName = wareReceieInfo.wName; history.WareRelativeType = wareReceieInfo.wType; } history.Quantity = quantity; history.IsSuccess = 1; history.Messenge = "Đã xuất kho"; return(history); }
public void read(MemoryStream msdata) { PHistory.readLoop(msdata, history); }
public ResultCodeEvent SendCodeEvent() { // send code // /api/rest/sendcodeevent var history = new MongoHistoryAPI() { CreateTime = DateTime.Now, APIUrl = "/api/event/sendcodeevent", Sucess = 1 }; var result = new ResultCodeEvent() { id = "1" }; var requestContent = Request.Content.ReadAsStringAsync().Result; history.Content = requestContent; try { var jsonserializer = new JavaScriptSerializer(); var paser = jsonserializer.Deserialize <RequestCodeEvent>(requestContent); history.Content = new JavaScriptSerializer().Serialize(paser); if (!mongoHelper.checkLoginSession(paser.user, paser.token)) { throw new Exception("Tài khoản bạn đã đăng nhập ở thiết bị khác."); } var cInfo = db.CInfoCommons.Where(p => p.UserLogin == paser.user).FirstOrDefault(); if (cInfo == null) { throw new Exception("Chương trình chỉ dành cho khách hàng của HAI."); } if (cInfo.CType == "CI") { throw new Exception("Chương trình chỉ dành cho khách hàng là đại lý cấp 2, nông dân của HAI."); } var dateNow = DateTime.Now; // lay danh sach sự kiện phù hợp với user (theo khu vực) List <EventInfo> listEventUser = new List <EventInfo>(); if (cInfo.CType == "CII") { // var eventArea = db.EventAreas.Where(p => p.AreaId == cInfo.AreaId && p.EventInfo.ESTT == 1).ToList(); var eventArea = (from log in db.EventAreas where log.EventInfo.ESTT == 1 && (DbFunctions.TruncateTime(log.EventInfo.BeginTime) <= DbFunctions.TruncateTime(dateNow) && DbFunctions.TruncateTime(log.EventInfo.EndTime) >= DbFunctions.TruncateTime(dateNow)) select log).ToList(); foreach (var item in eventArea) { var cusJoin = db.EventCustomers.Where(p => p.EventId == item.EventId).ToList(); if (cusJoin.Count() > 0) { var cJoin = cusJoin.Where(p => p.CInfoId == cInfo.Id).FirstOrDefault(); if (cJoin != null) { listEventUser.Add(item.EventInfo); } } else { //var cJoin = cusJoin.Where(p => p.CInfoId == cInfo.Id && p.IsJoint == 0).FirstOrDefault(); // if (cJoin == null) listEventUser.Add(item.EventInfo); } } } else if (cInfo.CType == "FARMER") { // var eventArea = db.EventAreaFarmers.Where(p => p.AreaId == cInfo.AreaId && p.EventInfo.ESTT == 1).ToList(); var eventArea = (from log in db.EventAreaFarmers where log.EventInfo.ESTT == 1 && (DbFunctions.TruncateTime(log.EventInfo.BeginTime) <= DbFunctions.TruncateTime(dateNow) && DbFunctions.TruncateTime(log.EventInfo.EndTime) >= DbFunctions.TruncateTime(dateNow)) select log).ToList(); foreach (var item in eventArea) { var cusJoin = db.EventCustomerFarmers.Where(p => p.EventId == item.EventId).ToList(); if (cusJoin.Count() > 0) { var cJoin = cusJoin.Where(p => p.CInfoId == cInfo.Id).FirstOrDefault(); if (cJoin != null) { listEventUser.Add(item.EventInfo); } } else { listEventUser.Add(item.EventInfo); } } } if (listEventUser.Count() == 0) { throw new Exception("Không tìm thấy chương trình khuyến mãi nào phù hợp."); } List <GeneralInfo> listCodeReturn = new List <GeneralInfo>(); Hashtable map = new Hashtable(); foreach (var item in paser.codes) { try { // lây mã seri // eventCode or seri var product = GetProduct(item); if (product == null) { listCodeReturn.Add(new GeneralInfo() { name = "Không phải sản phẩm HAI", code = item, status = "Mã không hợp lệ" }); throw new Exception(); } var caseCode = item.Substring(0, 15); var boxCode = item.Substring(0, 16); // kiem tra la da nhap kho chua PHistory pHis = null; if (product.IsBox == 1) { pHis = db.PHistories.Where(p => p.BoxCode == boxCode && p.WCode == cInfo.CCode && p.PStatus == "NK").FirstOrDefault(); } else { pHis = db.PHistories.Where(p => p.CaseCode == caseCode && p.WCode == cInfo.CCode && p.PStatus == "NK").FirstOrDefault(); } if (pHis == null) { listCodeReturn.Add(new GeneralInfo() { name = product.PName, code = item, status = "Mã chưa nhập kho" }); throw new Exception(); } // kiem tra la da su dung chua var checkUse = db.MSGPoints.Where(p => p.Barcode == item).FirstOrDefault(); if (checkUse != null) { listCodeReturn.Add(new GeneralInfo() { name = product.PName, code = item, status = "Mã đã được sử dụng" }); throw new Exception(); } // cap nhat lịch su var hEvent = new MSGPoint() { Id = Guid.NewGuid().ToString(), AcceptTime = DateTime.Now, CInfoId = cInfo.Id, UserLogin = paser.user, ProductId = product.Id, Barcode = item, MSGType = "APP" }; List <MSGPointEvent> listPointEvent = new List <MSGPointEvent>(); foreach (var userEvent in listEventUser) { // kiem tra san pham co trong su kien nay ko var productEvent = userEvent.EventProducts.Where(p => p.ProductId == product.Id).FirstOrDefault(); if (productEvent != null) { var pointEvemt = new MSGPointEvent() { EventId = userEvent.Id, MSGPointId = hEvent.Id, Point = productEvent.Point }; listPointEvent.Add(pointEvemt); // tra thong tin ve client listCodeReturn.Add(new GeneralInfo() { code = item, name = product.PName, status = productEvent.EventInfo.Name + " + " + productEvent.Point + "***" }); } } // if (listPointEvent.Count() > 0) { db.MSGPoints.Add(hEvent); db.SaveChanges(); foreach (var pevent in listPointEvent) { if (map.ContainsKey(pevent.EventId)) { var oldPoint = Convert.ToInt32(map[pevent.EventId]); map[pevent.EventId] = oldPoint + pevent.Point; } else { map.Add(pevent.EventId, Convert.ToInt32(pevent.Point)); } db.MSGPointEvents.Add(pevent); // luu diem cho khach hang var agencyPoint = db.AgencySavePoints.Where(p => p.EventId == pevent.EventId && p.CInfoId == cInfo.Id).FirstOrDefault(); if (agencyPoint == null) { var newAgencyPoint = new AgencySavePoint() { EventId = pevent.EventId, CInfoId = cInfo.Id, PointSave = pevent.Point, CreateTime = DateTime.Now }; db.AgencySavePoints.Add(newAgencyPoint); } else { var newPoint = agencyPoint.PointSave + pevent.Point; agencyPoint.PointSave = newPoint; agencyPoint.ModifyTime = DateTime.Now; db.Entry(agencyPoint).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); } } } catch { } } string pointEvent = ""; int countPoint = 0; foreach (var item in map.Keys) { var eventInfo = db.EventInfoes.Find(item); var savePoint = eventInfo.AgencySavePoints.Where(p => p.CInfoCommon.UserLogin == paser.user).FirstOrDefault(); int?point = 0; if (savePoint != null) { point = savePoint.PointSave; } string aWard = ""; var listAward = eventInfo.AwardInfoes.ToList(); foreach (var aWardItem in listAward) { if (aWardItem.Point <= point) { aWard += ", " + aWardItem.Name + "(" + aWardItem.Point + "điểm )"; } } var nameEvent = eventInfo.Name; pointEvent = pointEvent + ";" + nameEvent + " (" + map[item] + " điểm)"; if (!String.IsNullOrEmpty(aWard)) { aWard = aWard.Remove(0, 2); pointEvent = pointEvent + " - phần thưởng đổi: " + aWard; } else { pointEvent = pointEvent + "-chưa đủ điểm đổi quà"; } countPoint += Convert.ToInt32(map[item]); } string msgReturn = "Cộng " + countPoint; msgReturn = msgReturn + pointEvent; result.msg = msgReturn; result.codes = listCodeReturn; } catch (Exception e) { result.id = "0"; result.msg = e.Message; history.Sucess = 0; } mongoHelper.createHistoryAPI(history); return(result); }