コード例 #1
0
ファイル: dbSynchronizer.cs プロジェクト: AramisIT/Lamps
        /// <summary>Синхронизировать документы "Приемка нового компл." с сервера</summary>
        private void SyncAccepmentsDocFromServer()
        {
            DataTable acceptedDoc    = AcceptanceOfNewComponents.GetAcceptedDocuments();
            DataTable notAcceptedDoc = AcceptanceOfNewComponents.GetNotAcceptedDocuments();

            PerformQuery("GetAcceptDocs", acceptedDoc, notAcceptedDoc);

            if (IsExistParameters)
            {
                AcceptanceOfNewComponents.ClearAcceptedDocuments();
                DataTable table = ResultParameters[0] as DataTable;

                if (table != null)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        string contractorBarcode = row["Contractor"].ToString();
                        string partyRef          = row["InvoiceNumber"].ToString();
                        string caseModelRef      = row["CaseModel"].ToString();
                        string lampModelRef      = row["LampModel"].ToString();
                        string unitModelRef      = row["UnitModel"].ToString();
                        object contractorObj     = BarcodeWorker.GetIdByBarcode(typeof(Contractors), contractorBarcode);
                        object partyObj          = BarcodeWorker.GetIdByRef(typeof(Party), partyRef);
                        object caseModelObj      = BarcodeWorker.GetIdByRef(typeof(Models), caseModelRef);
                        object lampModelObj      = BarcodeWorker.GetIdByRef(typeof(Models), lampModelRef);
                        object unitModelObj      = BarcodeWorker.GetIdByRef(typeof(Models), unitModelRef);

                        AcceptanceOfNewComponents doc = new AcceptanceOfNewComponents
                        {
                            Id               = Convert.ToInt64(row["Id"]),
                            Contractor       = Convert.ToInt64(contractorObj),
                            Date             = Convert.ToDateTime(row["Date"]),
                            InvoiceDate      = Convert.ToDateTime(row["InvoiceDate"]),
                            InvoiceNumber    = Convert.ToInt64(partyObj),
                            MarkForDeleting  = false,
                            CaseModel        = Convert.ToInt64(caseModelObj),
                            LampModel        = Convert.ToInt64(lampModelObj),
                            UnitModel        = Convert.ToInt64(unitModelObj),
                            TypesOfWarrantly = (TypesOfLampsWarrantly)
                                               Convert.ToInt32(row["TypesOfWarrantly"]),
                            TypeOfAccessories = (TypeOfAccessories)
                                                Convert.ToInt32(row["TypeOfAccessories"]),
                            WarrantlyHours = Convert.ToInt32(row["WarrantlyHours"]),
                            WarrantlyYears = Convert.ToInt32(row["WarrantlyYears"]),
                            State          = (TypesOfLampsStatus)Convert.ToInt32(row["State"])
                        };
                        doc.Sync <AcceptanceOfNewComponents>();
                    }
                }
            }
        }
コード例 #2
0
        private void ok_Click()
        {
            object caseId = BarcodeWorker.GetIdByBarcode(CaseBarcode);
            //Статус корпуса, в который запихиваем новое комплектующее
            TypesOfLampsStatus status = Accessory.GetState(TypeOfAccessories.Case, CaseBarcode.ToString());
            bool   isLamp             = accessoryTable == typeof(db.Lamps).Name;
            object accessoryId        = BarcodeWorker.GetIdByBarcode(NewAccessoryBarcode.ToString());

            string command = string.Format(
                "UPDATE {0} SET Status=@IsWorking,[Case]=@Case,{1}=0,DateOfActuality=@Date{2} WHERE RTRIM(BarCode)=@Barcode",
                accessoryTable,
                dbObject.IS_SYNCED,
                isLamp ? ",Barcode=@NewBarCode" : string.Empty);

            using (SqlCeCommand query = dbWorker.NewQuery(command))
            {
                query.AddParameter("Barcode", NewAccessoryBarcode);
                query.AddParameter("NewBarCode", string.Empty);
                query.AddParameter("Case", caseId);
                query.AddParameter("IsWorking", status);
                query.AddParameter("Date", DateTime.Now);
                query.ExecuteNonQuery();
            }

            using (SqlCeCommand query = dbWorker.NewQuery(string.Format(
                                                              "UPDATE Cases SET {0}=@Id,{1}=0,DateOfActuality=@Date WHERE RTRIM(BarCode)=@Case",
                                                              accessoryField,
                                                              dbObject.IS_SYNCED)))
            {
                query.AddParameter("Case", CaseBarcode);
                query.AddParameter("Id", accessoryId);
                query.AddParameter("Date", DateTime.Now);
                query.ExecuteNonQuery();
            }
            //query = dbWorker.NewQuery(string.Format(
            //    "UPDATE {0} SET Status=@IsWorking,[Case]=@Id,{1}=0,DateOfActuality=@Date WHERE {2}=@Id",
            //    accessoryTable,
            //    dbObject.IS_SYNCED,
            //    dbObject.IDENTIFIER_NAME));
            //query.AddParameter("Id", caseId);
            //query.AddParameter(dbObject.IDENTIFIER_NAME, accessoryId);
            //query.AddParameter("Date", DateTime.Now);
            //query.ExecuteNonQuery();

            //string caseBarcode = CaseBarcode.ToString();
            //installMovement(caseBarcode);
            OnHotKey(KeyAction.Esc);
        }
コード例 #3
0
        private void finish(bool isForExchange)
        {
            object[] result = null;
            //Штрихкод установленной лампы
            using (SqlCeCommand query = dbWorker.NewQuery(string.Format(@"
SELECT a.Barcode, a.SyncRef
FROM Cases c
LEFT JOIN {0} a ON a.Id=c.{1}
WHERE RTRIM(c.BarCode)=@BarCode", accessoryTable, accessoryTable.Substring(0, accessoryTable.Length - 1))))
            {
                query.AddParameter("BarCode", CaseBarcode);
                result = query.SelectArray();
            }

            if (result != null && result.Length == 2)
            {
                object oldLampBarcode = result[0];
                object accessoryRef   = result[1];
                object caseId         = BarcodeWorker.GetIdByBarcode(CaseBarcode);
                object newAccessoryId = BarcodeWorker.GetIdByBarcode(NewAccessoryBarcode);
                bool   isLamp         = accessoryTable == typeof(db.Lamps).Name;

                string partOfCommand = string.Format(
                    "UPDATE {0} SET Status=@Status{1},[Case]=@Case,{2}=0,DateOfActuality=@Date{3} WHERE ",
                    accessoryTable,
                    type != TypeOfAccessories.ElectronicUnit
                        ? ", Barcode=@NewBarcode "
                        : string.Empty,
                    dbObject.IS_SYNCED,
                    "{0}");

                //Статус комплектующего, которое меняем
                TypesOfLampsStatus status = Accessory.GetState(TypeOfAccessories.Lamp, oldLampBarcode.ToString());

                //Старое комплектующее
                using (SqlCeCommand query = dbWorker.NewQuery(string.Concat(
                                                                  string.Format(partOfCommand, ",DrawdownDate=@DrawdownDate"),
                                                                  " RTRIM(SyncRef)=RTRIM(@SyncRef)")))
                {
                    query.AddParameter("Status",
                                       isForExchange ? TypesOfLampsStatus.ToRepair : TypesOfLampsStatus.Storage);
                    query.AddParameter("Case", 0);
                    query.AddParameter("LampBarcode", oldLampBarcode);
                    query.AddParameter("NewBarcode", isLamp ? NewAccessoryBarcode : oldLampBarcode);
                    query.AddParameter(dbObject.SYNCREF_NAME, accessoryRef);
                    query.AddParameter("Date", DateTime.Now);
                    query.AddParameter("DrawdownDate", DateTime.Now);
                    query.ExecuteNonQuery();
                }

                //Новое комплектующее
                using (
                    SqlCeCommand query =
                        dbWorker.NewQuery(string.Concat(string.Format(partOfCommand, string.Empty), " Id=@Id")))
                {
                    query.AddParameter("Status", status);
                    query.AddParameter("Case", caseId);
                    query.AddParameter("Id", newAccessoryId);
                    query.AddParameter("NewBarcode", isLamp ? string.Empty : oldLampBarcode);
                    query.AddParameter("Date", DateTime.Now);
                    query.ExecuteNonQuery();
                }

                //Замена комплектующего в светильнике
                using (SqlCeCommand query = dbWorker.NewQuery(string.Format(
                                                                  "UPDATE CASES SET {0}=@NewAccessoryId,{1}=0,DateOfActuality=@Date WHERE RTRIM(BarCode)=RTRIM(@CaseBarcode)",
                                                                  accessoryField,
                                                                  dbObject.IS_SYNCED)))
                {
                    query.AddParameter("CaseBarcode", CaseBarcode);
                    query.AddParameter("NewAccessoryId", newAccessoryId);
                    query.AddParameter("Date", DateTime.Now);
                    query.ExecuteNonQuery();
                }
                //Завершение
                //string caseBarcode = CaseBarcode.ToString();
                //installMovement(caseBarcode);
                //removeMovement(oldLampBarcode.ToString(), caseBarcode);
                OnHotKey(KeyAction.Esc);
            }
        }