Esempio n. 1
0
        /** Register the user onto a server.
         *
         * 用户注册/登录 (由于钱包功能尚不支持,Demo阶段暂时使用用户邮箱/密码作为认证方法。若有变动将在Global.VerifyUser()方法里变更实现)
         * 返回:该用户所有卡牌具体信息。若在该服务器上新账户,为用户新建若干卡牌。
         *
         * Check psw/signature first, then
         * If the user does exist already,
         *      If user exist on current server, consider as login in.
         *      If user does exist on another server, transfer user to this server.
         * Else, create cards for this user. Need attach some GAS...
         *
         * Return: S<header>
         *
         */
        private static byte[] Register(Credential credential, BigInteger serverId, string nickName, BigInteger iconID)
        {
            byte[] userData = RW.FindDataUser(credential.email);
            if (userData.Length != 0)
            {   //Exists
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.Duplicated));
            }
            else
            {
                byte[] psdHash = Hash256(Op.String2Bytes(credential.psw));
                User   user    = new User();
                user.address  = credential.address;
                user.email    = credential.email;
                user.pswHash  = psdHash;
                user.nickName = nickName;
                user.icon     = iconID;
                user.serverID = serverId;
                user.warID    = Op.Void();
                user.city     = Const.numCities;
                //user.cardIDs = new byte[0];

                RW.SaveUser(user);
                return(NuTP.RespDataSucWithBody(RW.User2Bytes(user)));
            }
        }
Esempio n. 2
0
        // <emails> = [S<email>*]
        //<FakeUsers> = [S<user>*]
        private static byte[] FakeUsers(BigInteger serverId, byte[] emails)
        {
            byte[] body = Op.Void();

            if (Runtime.CheckWitness(Owner))
            {
                int numEmails = emails.SizeTable();
                for (int i = 0; i < numEmails; i++)
                {
                    string email = NuSD.SplitTblStr(emails, i);
                    User   user  = new User
                    {
                        address  = Op.Void(),
                        email    = email,
                        pswHash  = Op.Void(),
                        nickName = "Fake",
                        icon     = 0,
                        serverID = serverId,
                        warID    = Op.Void(),
                        city     = Const.numCities
                    };
                    user.cards = GenerateRandomCards(user, 10);
                    RW.SaveUser(user);
                    body.AddSeg(RW.User2Bytes(user));
                }

                return(NuTP.RespDataSucWithBody(body));
            }
            else
            {
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.AuthFail));
            }
        }
Esempio n. 3
0
        /** Get basic information of a list of users
         *
         *  获取一系列玩家信息, 内容包括所在服务器、所占城池、
         * 返回:该用户所有卡牌具体信息。
         *
         * For each user, the information includes:
         *     -  User email and address,
         *     -  User current server and city
         *     -  User score and unclaimed score
         *     -  User's cards (full cards data)
         *
         * Return: Array of the User objects and cards
         *
         *
         */

        /* * NuTP:
         * <emails> = S[S<email>*]
         *
         * <getUsers> =  [S<header>,
         *             S[([S<user>,
         *                  S[S<card>*10]]
         *             )*]
         */

        private static byte[] GetUsers(Credential credential, byte[] emails)
        {
            // This method does not require credential

            int numEmails = emails.SizeTable();

            byte[] retBody = Op.Void();

            for (int i = 0; i < numEmails; i++)
            {
                string email = emails.SplitTblStr(i);
                User   user  = RW.FindUser(email);
                if (user != null)
                {
                    byte[] body = NuSD.Seg(RW.User2Bytes(user)).AddSeg(RW.UserCards2Table(user));
                    retBody.AddSeg(body);
                }
                else
                {
                    return(NuTP.RespDataWithDetail(ErrCate.User, ErrType.NotExist, email, Op.Void()));
                }
            }

            NuTP.Response response = new NuTP.Response
            {
                header = new NuTP.Header
                {
                    domain = NuTP.SysDom,
                    code   = NuTP.Code.Success
                },

                body = retBody
            };
            return(NuTP.Response2Bytes(response));
        }
Esempio n. 4
0
        /// <summary>
        /// 给指定用户产生随机初始卡
        /// 返回实际生成的卡牌数量
        /// </summary>
        public static Card[] GenerateRandomCards(User user, int num)
        {
            Card[] cards           = new Card[num];
            int    numCardsAlready = 0;

            if (user.cards != null && user.cards.Length > 0)
            {
                numCardsAlready = user.cards.Length;
            }

            byte[] dHeight = Op.BigInt2Bytes(Blockchain.GetHeight());
            byte[] salt    = Rand();
            for (int i = 0; i < num; i++)
            {
                Card   cardResult = new Card();
                byte[] dEmail     = Op.String2Bytes(user.email);
                byte[] dNum       = Op.BigInt2Bytes(i + numCardsAlready);

                cardResult.cardID = Random(Op.JoinByteArray(dEmail, dNum, dHeight), 10);

                cardResult.type = Op.Bytes2BigInt(Hash160(cardResult.cardID)) % TypeArmy.TypeCount;
                cardResult.lvls = Random(salt, Const.numCellsOfCard);

                cardResult.ownerEmail = user.email;
                cardResult.warPos     = 0;
                cards[i] = cardResult;
                RW.SaveCard(cardResult);
            }

            return(cards);
        }
Esempio n. 5
0
        public void CopyRW()
        {
            conf Config = new conf();

            try
            {
                File.Copy(pdfName, Config.outPath + "Rok_20" + year + "\\RW\\" + docName + ".pdf");
                StreamWriter RW;
                RW = File.AppendText(fileLog);
                RW.WriteLine(Config.outPath + "Rok_20" + year + "\\RW\\" + docName + ".pdf");
                RW.Close();
            }
            catch (IOException)
            {
                FileInfo infoFirst  = new FileInfo(Config.outPath + "Rok_20" + year + "\\RW\\" + docName + ".pdf");
                long     byteFirst  = infoFirst.Length;
                FileInfo infoSecond = new FileInfo(pdfName);
                long     byteSecond = infoSecond.Length;
                if (byteFirst != byteSecond)
                {
                    File.Copy(pdfName, Config.outPath + "Rok_20" + year + "\\duplikaty\\" + docName + ".pdf");
                    StreamWriter RW2;
                    RW2 = File.AppendText(fileLog);
                    RW2.WriteLine("!! DUPLIKAT !!    " + Config.outPath + "Rok_20" + year + "\\duplikaty\\" + docName + ".pdf" + "    !! DUPLIKAT !!");
                    RW2.Close();
                }
                else
                {
                    StreamWriter RW3;
                    RW3 = File.AppendText(fileLog);
                    RW3.WriteLine("!! Identyczny plik istnieje !!    " + Config.outPath + "Rok_20" + year + "\\" + docName + ".pdf" + "    !! Identyczny plik istnieje !!");
                    RW3.Close();
                }
            }
        }
        public int RozpocznijDekompletacje()
        {
            NowyDokument(RW);
            WartoscRW      = RW.WartoscDokumentu;
            ZwracaneWyniki = RW.GetReturns();
            List <int> _ZwracaneWyniki = new List <int>();

            _ZwracaneWyniki.AddRange(ZwracaneWyniki);

            if (SprawdzPoprawnoscDokumentu())
            {
                NowyDokument(PW);
                _ZwracaneWyniki.AddRange(PW.GetReturns());
                return(_ZwracaneWyniki.Sum());
            }
            else
            {
                info.Sukces    = false;
                info.Komunikat = "Różnica wartości dokumentów RW / PW jest zbyt duża.Wszystkie dokumenty dekompletacji zostaną cofnięte.";
                info.Rodzic    = true;

                RW.NotifyObservers(info);
                AnulujDekompletacje();
                _ZwracaneWyniki.AddRange(ZwracaneWyniki);
                return(_ZwracaneWyniki.Sum());
            }
        }
Esempio n. 7
0
        byte[] formSlaveAddrFrame(byte slave_addr, RW R_W)
        {
            List <byte> buffer = new List <byte>();

            buffer.Add(MSB_FALLING_EDGE_CLOCK_BYTE_OUT); // clock data byte on clock edge MSB first
            buffer.Add(0x00);                            // data length of 0x0000 means 1 byte
            buffer.Add(0x00);

            // Shift by 1 bit and add Read/Write bit at end
            byte data = (byte)((slave_addr << 1) | (Convert.ToByte(R_W) & 0x1));

            data = (byte)(data | 0x80);
            buffer.Add(data);

            // SDA tristate, SCL low
            buffer.AddRange(formSetDataBits(BUS.ADBUS, 0x02, 0x01));

            // Clock for ACK
            buffer.Add(MSB_RISING_EDGE_CLOCK_BIT_IN); // Command to clock in bits MSB first on rising edge
            buffer.Add(0x00);                         // length of 0x00 means scan 1 bit
            buffer.Add(0x87);                         //Send answer back immediate command

            //// Reset pin state
            buffer.AddRange(formSetDataBits(BUS.ADBUS, 0x02, 0x03));

            return(buffer.ToArray());
        }
Esempio n. 8
0
 public void SaveRW(RW rozchodwewnetrzny)
 {
     if (rozchodwewnetrzny.RWID == 0)
     {
         context.RWs.Add(rozchodwewnetrzny);
         context.SaveChanges();
     }
 }
Esempio n. 9
0
        /** All the completed wars related with particular user with "maximum" recent items.
         *
         * 获取某用户已完成战役列表(最近的maximum个)。返回:一组War的列表
         *
         *
         * Return: Array of War Object
         */
        private static byte[] GetUserSeiges(Credential credential, string email, BigInteger maximum)
        {
            User       user = RW.FindUser(email);
            BigInteger tot  = RW.NumUserSiegeHistory(user);
            BigInteger num  = (tot > maximum) ? maximum : tot;

            return(NuTP.RespDataWithCode(NuTP.SysDom, NuTP.Code.ServiceUnavailable));
        }
Esempio n. 10
0
 /** All cities in a server with "maximum" recent items.
  *
  * 获取城市状态列表
  *
  * Return: Array of War Object
  */
 private static byte[] GetCities(Credential credential, BigInteger serverId)
 {
     byte[] body = Op.Void();
     for (int i = 0; i < Const.numCities; i++)
     {
         body.AddSeg(RW.FindDataCity(serverId, i));
     }
     return(NuTP.RespDataSucWithBody(body));
 }
Esempio n. 11
0
 public TypeAttribute(Types type, RW rWStatus, int length = 1, string sourceFunction = "", bool notify = false, bool isUnsign = false)
 {
     Type           = type;
     Length         = length;
     RWStatus       = rWStatus;
     SourceFunction = sourceFunction;
     Notify         = notify;
     IsUnsign       = isUnsign;
 }
Esempio n. 12
0
        public void CopyOther()
        {
            conf Config = new conf();

            File.Copy(pdfName, Config.inPath + "\\!do_przetworzenia_recznego\\" + docName);
            StreamWriter RW;

            RW = File.AppendText(fileLog);
            RW.WriteLine(Config.inPath + "\\!do_przetworzenia_recznego\\" + docName);
            RW.Close();
        }
Esempio n. 13
0
 public static byte[] SetWeather(byte[] weathers)
 {
     if (Runtime.CheckWitness(Owner))
     {
         RW.SaveWeathers(weathers);
         return(NuTP.RespDataSuccess());
     }
     else
     {
         return(NuTP.RespDataWithCode(NuTP.SysDom, NuTP.Code.Forbidden));
     }
 }
 private void AnulujDekompletacje()
 {
     if (PW.StanDokumentu != -1 && PW.DokumentNumer != 0)
     {
         PW.AnulujDokument();
         ZwracaneWyniki = PW.GetReturns();
         RW.AnulujDokument();
     }
     else if (RW.StanDokumentu == -1 && RW.DokumentNumer != 0)
     {
         RW.AnulujDokument();
     }
 }
Esempio n. 15
0
        /** User starts a war against a city. If the city is empty now, it's gonna occupy it directly.
         * 参战某城市,
         * Return: An object of War. If failed to create, return null
         */
        /** User starts a war against a city. If the city is empty now, it's gonna occupy it directly.
         * 参战某城市,
         * Return: An object of War. If failed to create, return null
         */
        public static byte[] StartSiege(Credential credential, BigInteger serverId, BigInteger cityId, byte[] cardIds)
        {
            if (Global.VerifyUser(credential))
            {
                if (cityId >= Const.numCities)
                {
                    return(NuTP.RespDataWithCode(ErrCate.City, ErrType.NotExist));
                }
                else
                {   //City does exist
                    City       city   = RW.FindCity(serverId, cityId);
                    BigInteger status = RW.GetStatusCity(city);
                    if (status == StatusCity.Sieging)
                    {
                        return(NuTP.RespDataWithCode(ErrCate.City, ErrType.Duplicated));
                    }
                    else
                    {
                        User user = RW.FindUser(credential.email);
                        if (user.warID != Op.Void())
                        {  //User does not allow to participate into multiple wars at the same time
                            return(NuTP.RespDataWithCode(ErrCate.War, ErrType.Duplicated));
                        }
                        else
                        {
                            CarryBattleSC.Card[] cards = RW.Table2Cards(cardIds);
                            if (cards.Length != Const.numCardsSiege)
                            {  //Format of card array must be wrong
                                return(NuTP.RespDataWithCode(NuTP.SysDom, NuTP.Code.BadRequest));
                            }

                            for (int i = 0; i < Const.numCardsSiege; i++)
                            {
                                if (cards[i].ownerEmail != user.email)
                                {
                                    return(NuTP.RespDataWithCode(ErrCate.Card, ErrType.NotExist));
                                }
                            }

                            Siege siege = RW.CreateSiege(serverId, city, user, cards, Blockchain.GetHeight());

                            return(NuTP.RespDataSucWithBody(RW.Seige2Bytes(siege)));
                        }
                    }
                }
            }
            else
            {
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.AuthFail));
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 获取SqlMapper。
        /// </summary>
        /// <param name="rw">读-写库选择</param>
        /// <returns>SqlMapper对象</returns>
        public ISqlMapper this[RW rw]
        {
            get
            {
                var result = this._isReadWriteSpliting ?
                    (rw == RW.Read ? this._reader : this._writer) : this._reader;

                var callContextSessionStore = new CallContextSessionStore(result.Id);

                result.SessionStore = callContextSessionStore;

                return result;
            }
        }
        private bool SprawdzPoprawnoscDokumentu()
        {
            ZwracaneWyniki = RW.GetReturns();
            var wartoscPW = ListaTowarowPW.Sum(k => k.Cena * k.Ilosc);

            if (SprawdzMarginesBleduRWPW(WartoscRW, wartoscPW) <= 0.20m && ZwracaneWyniki.Sum() == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 18
0
        /** Get basic information of an user
         *
         *  获取一个玩家信息, 内容包括所在服务器、所占城池、
         * 返回:该用户所有卡牌具体信息。
         *
         * The information includes:
         *     -  User email and address,
         *     -  User current server and city
         *     -  User score and unclaimed score
         *     -  User's cards (full cards data)
         *
         * Return: Array of the User objects and cards
         *
         *
         */

        /* * NuTP:
         * <GetUsers> =  [S<header>, S<user>, S[S<card>*]]
         *
         */

        private static byte[] GetUser(Credential credential, string email)
        {
            // This method does not require credential

            User user = RW.FindUser(email);

            if (user != null)
            {
                byte[] body = NuSD.Seg(RW.User2Bytes(user)).AddSeg(RW.UserCards2Table(user));
                return(NuTP.RespDataSucWithBody(body));
            }
            else
            {
                return(NuTP.RespDataWithDetail(ErrCate.User, ErrType.NotExist, email, Op.Void()));
            }
        }
Esempio n. 19
0
        /* * NuTP:
         *
         * <RegCards> =  [S<header>, S[S<card>*]]
         *
         */
        private static byte[] RegCards(Credential credential, int num)
        {
            byte[] userData = RW.FindDataUser(credential.email);
            if (userData.Length == 0)
            {   //Account Not exist
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.NotExist));
            }
            else
            {   //Account does exist
                User user       = RW.Bytes2User(userData);
                int  numAlready = RW.NumCardsOfUser(user);
                int  numPending = Const.numCardsTotalReg - numAlready;
                if (numPending <= 0)
                {
                    return(NuTP.RespDataWithCode(ErrCate.Card, ErrType.Duplicated));
                }
                else
                {
                    CarryBattleSC.Card[] cardsNew  = GenerateRandomCards(user, (numPending < Const.numCardsPerReg) ? numPending : Const.numCardsPerReg);
                    CarryBattleSC.Card[] cardsOrig = user.cards;
                    user.cards = new CarryBattleSC.Card[cardsOrig.Length + cardsNew.Length];


                    for (int i = 0; i < cardsOrig.Length; i++)
                    {
                        user.cards[i] = cardsOrig[i];
                    }

                    for (int j = 0; j < cardsNew.Length; j++)
                    {
                        user.cards[j + cardsOrig.Length] = cardsNew[j];
                    }
                    //更新玩家数据
                    RW.SaveUser(user);

                    byte[] body = RW.UserCards2Table(user);
                    return(NuTP.RespDataSucWithBody(body));
                }
            }
        }
Esempio n. 20
0
        private static byte[] FakeOccupies(BigInteger serverId, string email, BigInteger cityID)
        {
            if (Runtime.CheckWitness(Owner))
            {
                if (cityID > Const.numCities || cityID <= 0)
                {
                    return(NuTP.RespDataWithCode(ErrCate.City, ErrType.NotExist));
                }
                else
                {
                    User user = RW.FindUser(email);
                    if (user != null)
                    {
                        City city = RW.FindCity(serverId, cityID);
                        if (city.ownerID.Length == 0 || city.ownerID.Length == 1) //something wrong with bytes2string/string2bytes
                        {                                                         //not work when it's not occupied
                            city.ownerID = email;
                            RW.SaveCity(serverId, city);

                            user.city = cityID;
                            RW.SaveUser(user);
                            return(NuTP.RespDataSuccess());
                        }
                        else
                        {
                            return(NuTP.RespDataWithCode(ErrCate.City, ErrType.Duplicated));
                        }
                    }
                    else
                    {
                        return(NuTP.RespDataWithCode(ErrCate.User, ErrType.NotExist));
                    }
                }
            }
            else
            {
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.AuthFail));
            }
        }
Esempio n. 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="slave_addr">The slave address is determine by A0 and A1 pins, so only last 4 bits</param>
        /// <param name="R_W">true = read, false = write command</param>
        /// <param name="register_pointer">register address</param>
        public void RegisterPointerSet(byte slave_addr, RW R_W, byte register_pointer)
        {
            List <byte> buffer = new List <byte>();

            // Start - Slave addr
            buffer.AddRange(formStart());                         // Start
            buffer.AddRange(formSlaveAddrFrame(slave_addr, R_W)); // Slave addr + R/W

            // Register address
            buffer.AddRange(formDataFrame(register_pointer));

            // Stop
            buffer.AddRange(formStop()); // Stop

            // Send command
            rawWrite(buffer.ToArray());


            uint count = waifForRxDataCount(2);

            byte[] readdata = rawRead(count);
            // readdata should be all 0 for all acks
        }
Esempio n. 22
0
        static void Drawing_OnDraw(EventArgs args)
        {
            if (Player.IsDead)
            {
                return;
            }

            var drawQ = AIO_Menu.Champion.Drawings.Qrange;
            var drawW = AIO_Menu.Champion.Drawings.Wrange;
            var drawE = AIO_Menu.Champion.Drawings.Erange;

            if (Q.IsReady() && drawQ.Active && HAMMER)
            {
                Render.Circle.DrawCircle(Player.Position, Q.Range, drawQ.Color);
            }
            if (W.IsReady() && drawW.Active && HAMMER)
            {
                Render.Circle.DrawCircle(Player.Position, W.Range, drawW.Color);
            }
            if (E.IsReady() && drawE.Active && HAMMER)
            {
                Render.Circle.DrawCircle(Player.Position, E.Range, drawE.Color);
            }
            if (RQ.IsReady() && drawQ.Active && !HAMMER)
            {
                Render.Circle.DrawCircle(Player.Position, RQ.Range, drawQ.Color);
            }
            if (RW.IsReady() && drawW.Active && !HAMMER)
            {
                Render.Circle.DrawCircle(Player.Position, RW.Range, drawW.Color);
            }
            if (E.IsReady() && drawE.Active && !HAMMER)
            {
                Render.Circle.DrawCircle(Player.Position, REQ.Range, drawE.Color);
            }
        }
Esempio n. 23
0
 /** All the completed wars related with particular user with "maximum" recent items.
  *
  * 获取某城市已完成战役列表(最近的maximum个)
  *
  *
  * Return: Array of War Object
  */
 private static byte[] GetCitySeiges(Credential credential, BigInteger serverId, BigInteger cityId, BigInteger maximum)
 {
     byte[] siegesData = RW.FindSiegesByCityHistory(serverId, cityId, maximum);
     return(NuTP.RespDataSucWithBody(siegesData));
 }
 private void btWrite_Click(object sender, System.EventArgs e)
 {
     m_direction = RW.WRITE;
     btClick();
 }
 private void btRead_Click(object sender, System.EventArgs e)
 {
     m_direction = RW.READ;
     btClick();
 }
Esempio n. 26
0
        public ActionResult DeleteZestaw(int productId)
        {
            DateTime localdate = DateTime.Now;

            Login uzytkwonik = repository2.Logins
                               .FirstOrDefault(p => p.LoginID == (int)Session["userID"]);

            Set zestawik = repository6.Sets
                           .FirstOrDefault(p => p.ProductID == productId);

            Product product = repository.Products
                              .FirstOrDefault(p => p.ProductID == productId);

            Product product1 = new Product();
            Product product2 = new Product();
            Product product3 = new Product();
            Product product4 = new Product();
            Product product5 = new Product();

            PW przychodwewmetrzny = new PW();
            RW rozchodwewnetrzny  = new RW();

            rozchodwewnetrzny.DataWystawienia = localdate;
            rozchodwewnetrzny.Miesiac         = localdate.Month;
            rozchodwewnetrzny.Rok             = localdate.Year;
            rozchodwewnetrzny.Wystawiajacy    = uzytkwonik.User;
            rozchodwewnetrzny.CenaCalkowita   = product.Price * product.Total;
            rozchodwewnetrzny.Produkty        = product.Name;


            przychodwewmetrzny.DataWystawienia = localdate;
            przychodwewmetrzny.Magazyn         = "Magazyn 1";
            przychodwewmetrzny.Miesiac         = localdate.Month;
            przychodwewmetrzny.Rok             = localdate.Year;
            przychodwewmetrzny.Wystawiajacy    = uzytkwonik.Name;
            przychodwewmetrzny.Produkt         = "";
            przychodwewmetrzny.Ilosc           = product.Total;
            przychodwewmetrzny.CenaCalkowita   = product.Price * product.Total;


            product1 = repository.Products
                       .FirstOrDefault(p => p.Name == zestawik.ProduktName1);
            product2 = repository.Products
                       .FirstOrDefault(p => p.Name == zestawik.ProduktName2);
            product3 = repository.Products
                       .FirstOrDefault(p => p.Name == zestawik.ProduktName3);
            product4 = repository.Products
                       .FirstOrDefault(p => p.Name == zestawik.ProduktName4);
            product5 = repository.Products
                       .FirstOrDefault(p => p.Name == zestawik.ProduktName5);


            var ilosc = product.Total;

            if (zestawik.ProduktName1 != null)
            {
                product1.Total             += product.Total;
                product1.Warehouse1        += product.Total;
                przychodwewmetrzny.Produkt += product.Name + "\t" + ilosc + "\n";
                repository.SaveProduct(product1);
            }

            if (zestawik.ProduktName2 != null)
            {
                product2.Total             += product.Total;
                product2.Warehouse1        += product.Total;
                przychodwewmetrzny.Produkt += product.Name + "\t" + ilosc + "\n";

                repository.SaveProduct(product2);
            }

            if (zestawik.ProduktName3 != null)
            {
                product3.Total             += product.Total;
                product3.Warehouse1        += product.Total;
                przychodwewmetrzny.Produkt += product.Name + "\t" + ilosc + "\n";

                repository.SaveProduct(product3);
            }
            if (zestawik.ProduktName4 != null)
            {
                product4.Total             += product.Total;
                product4.Warehouse1        += product.Total;
                przychodwewmetrzny.Produkt += product.Name + "\t" + ilosc + "\n";
                repository.SaveProduct(product4);
            }
            if (zestawik.ProduktName5 != null)
            {
                product5.Total             += product.Total;
                product5.Warehouse1        += product.Total;
                przychodwewmetrzny.Produkt += product.Name + "\t" + ilosc + "\n";
                repository.SaveProduct(product5);
            }



            repository8.SavePW(przychodwewmetrzny);
            repository10.SaveRW(rozchodwewnetrzny);

            Set deletedZestaw = repository6.DeleteZestaw(zestawik.SetID);

            Product deletedProduct = repository.DeleteProduct(productId);

            if (deletedProduct != null)
            {
                TempData["message"] = string.Format("Usunięto {0}", deletedProduct.Name);
            }
            return(RedirectToAction("Zestaw"));
        }
Esempio n. 27
0
        public ActionResult ŚciąganieProduktów(Product product)
        {
            DateTime localdate = DateTime.Now;
            Product  product2  = repository.Products
                                 .FirstOrDefault(p => p.ProductID == product.ProductID);

            Login uzytkwonik = repository2.Logins
                               .FirstOrDefault(p => p.LoginID == (int)Session["userID"]);

            RW rozchodwewnetrzny = new RW();

            rozchodwewnetrzny.DataWystawienia = localdate;
            rozchodwewnetrzny.Miesiac         = localdate.Month;
            rozchodwewnetrzny.Rok             = localdate.Year;
            rozchodwewnetrzny.Wystawiajacy    = uzytkwonik.User;
            rozchodwewnetrzny.Produkty        = product.Name + "\t" + (product.Warehouse1 + product.Warehouse2);
            rozchodwewnetrzny.CenaCalkowita   = product.Price * (product.Warehouse1 + product.Warehouse2);

            if (product.Warehouse1 == 0 && product.Warehouse2 == 0)
            {
                TempData["message"] = string.Format("Błąd danych. Spróbuj ponownie {0} ", product.Name);
                return(RedirectToAction("Index"));
            }
            else
            {
                if (product.Warehouse1 != 0)
                {
                    if (product.Warehouse1 > product2.Warehouse1)
                    {
                        TempData["message"] = string.Format("Błąd danych. Spróbuj ponownie {0} ", product.Name);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        product2.Warehouse1 -= product.Warehouse1;
                        product2.Total      -= product.Warehouse1;
                    }
                }

                if (product.Warehouse2 != 0)
                {
                    if (product.Warehouse2 > product2.Warehouse2)
                    {
                        TempData["message"] = string.Format("Błąd danych. Spróbuj ponownie {0} ", product.Name);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        product2.Warehouse2 -= product.Warehouse2;
                        product2.Total      -= product.Warehouse2;
                    }
                }


                product2.Total = product2.Warehouse1 + product2.Warehouse2;
                repository.SaveProduct(product2);
                repository10.SaveRW(rozchodwewnetrzny);

                TempData["message"] = string.Format("Zapisano {0} ", product.Name);

                return(RedirectToAction("Index"));
            }
        }
Esempio n. 28
0
        public ActionResult CreateZestaw(DodajProduktView dodaj)
        {
            DateTime localdate = DateTime.Now;
            Product  product   = new Product();
            Product  product1  = new Product();
            Product  product2  = new Product();
            Product  product3  = new Product();
            Product  product4  = new Product();
            Product  product5  = new Product();

            PW  przychodwewmetrzny = new PW();
            RW  rozchodwewnetrzny  = new RW();
            Set zestaw             = new Set();

            Login uzytkwonik = repository2.Logins
                               .FirstOrDefault(p => p.LoginID == (int)Session["userID"]);

            if (dodaj.zestaw.Name == null || dodaj.zestaw.ProduktName1 == null)
            {
                TempData["message"] = string.Format("Błąd danych. Spróbuj ponownie {0} ", dodaj.zestaw.Name);
                return(RedirectToAction("Zestaw"));
            }

            product.Category    = "Zestaw";
            product.Description = "Zestaw produktów:";
            product.Name        = dodaj.zestaw.Name;
            product.Price       = 0;
            product.Total       = dodaj.product.Total;
            product.Warehouse1  = dodaj.product.Total;
            product.Warehouse2  = 0;

            rozchodwewnetrzny.DataWystawienia = localdate;
            rozchodwewnetrzny.Miesiac         = localdate.Month;
            rozchodwewnetrzny.Rok             = localdate.Year;
            rozchodwewnetrzny.Wystawiajacy    = uzytkwonik.Name;
            rozchodwewnetrzny.CenaCalkowita   = 0;


            przychodwewmetrzny.DataWystawienia = localdate;
            przychodwewmetrzny.Magazyn         = "Magazyn 1";
            przychodwewmetrzny.Miesiac         = localdate.Month;
            przychodwewmetrzny.Rok             = localdate.Year;
            przychodwewmetrzny.Wystawiajacy    = uzytkwonik.Name;
            przychodwewmetrzny.Produkt         = dodaj.zestaw.Name;
            przychodwewmetrzny.Ilosc           = dodaj.product.Total;
            przychodwewmetrzny.CenaCalkowita   = 0;

            zestaw.Name         = dodaj.zestaw.Name;
            zestaw.ProduktName1 = dodaj.zestaw.ProduktName1;
            zestaw.ProduktName2 = dodaj.zestaw.ProduktName2;
            zestaw.ProduktName3 = dodaj.zestaw.ProduktName3;
            zestaw.ProduktName4 = dodaj.zestaw.ProduktName4;
            zestaw.ProduktName5 = dodaj.zestaw.ProduktName5;



            product1 = repository.Products
                       .FirstOrDefault(p => p.Name == dodaj.zestaw.ProduktName1);
            product2 = repository.Products
                       .FirstOrDefault(p => p.Name == dodaj.zestaw.ProduktName2);
            product3 = repository.Products
                       .FirstOrDefault(p => p.Name == dodaj.zestaw.ProduktName3);
            product4 = repository.Products
                       .FirstOrDefault(p => p.Name == dodaj.zestaw.ProduktName4);
            product5 = repository.Products
                       .FirstOrDefault(p => p.Name == dodaj.zestaw.ProduktName5);

            if (product1.Total < dodaj.product.Total)
            {
                TempData["message"] = string.Format("Nie wystarczająco produktów na magazynie {0} ", dodaj.zestaw.ProduktName1);
                return(RedirectToAction("Zestaw"));
            }
            else
            {
                var z = dodaj.product.Total;
                product1.Total -= dodaj.product.Total;
                if (product1.Warehouse1 < z)
                {
                    z -= product1.Warehouse1;
                    product1.Warehouse1  = 0;
                    product1.Warehouse2 -= z;
                }
                else
                {
                    product1.Warehouse1 -= z;
                }
                rozchodwewnetrzny.CenaCalkowita += product1.Price * dodaj.product.Total;
                rozchodwewnetrzny.Produkty      += product1.Name + "\t" + product1.Price + "\n";
                product.Description             += product1.Name + ",";
            }

            if (product2 != null)
            {
                if (product2.Total < dodaj.product.Total)
                {
                    TempData["message"] = string.Format("Nie wystarczająco produktów na magazynie {0} ", dodaj.zestaw.ProduktName2);
                    return(RedirectToAction("Zestaw"));
                }
                else
                {
                    var z = dodaj.product.Total;
                    product2.Total -= dodaj.product.Total;
                    if (product2.Warehouse1 < z)
                    {
                        z -= product1.Warehouse1;
                        product2.Warehouse1  = 0;
                        product2.Warehouse2 -= z;
                    }
                    else
                    {
                        product2.Warehouse1 -= z;
                    }
                    rozchodwewnetrzny.CenaCalkowita += product2.Price * dodaj.product.Total;
                    rozchodwewnetrzny.Produkty      += product2.Name + "\t" + product2.Price + "\n";
                    product.Description             += product2.Name + ",";
                }
            }

            if (product3 != null)
            {
                if (product3.Total < dodaj.product.Total)
                {
                    TempData["message"] = string.Format("Nie wystarczająco produktów na magazynie {0} ", dodaj.zestaw.ProduktName3);
                    return(RedirectToAction("Zestaw"));
                }
                else
                {
                    var z = dodaj.product.Total;
                    product3.Total -= dodaj.product.Total;
                    if (product3.Warehouse1 < z)
                    {
                        z -= product1.Warehouse1;
                        product3.Warehouse1  = 0;
                        product3.Warehouse2 -= z;
                    }
                    else
                    {
                        product3.Warehouse1 -= z;
                    }
                    rozchodwewnetrzny.CenaCalkowita += product3.Price * dodaj.product.Total;
                    rozchodwewnetrzny.Produkty      += product3.Name + "\t" + product3.Price + "\n";
                    product.Description             += product3.Name + ",";
                }
            }

            if (product4 != null)
            {
                if (product4.Total < dodaj.product.Total)
                {
                    TempData["message"] = string.Format("Nie wystarczająco produktów na magazynie {0} ", dodaj.zestaw.ProduktName4);
                    return(RedirectToAction("Zestaw"));
                }
                else
                {
                    var z = dodaj.product.Total;
                    product4.Total -= dodaj.product.Total;
                    if (product4.Warehouse1 < z)
                    {
                        z -= product1.Warehouse1;
                        product4.Warehouse1  = 0;
                        product4.Warehouse2 -= z;
                    }
                    else
                    {
                        product4.Warehouse1 -= z;
                    }
                    rozchodwewnetrzny.CenaCalkowita += product4.Price * dodaj.product.Total;
                    rozchodwewnetrzny.Produkty      += product4.Name + "\t" + product4.Price + "\n";
                    product.Description             += product4.Name + ",";
                }
            }

            if (product5 != null)
            {
                if (product5.Total < dodaj.product.Total)
                {
                    TempData["message"] = string.Format("Nie wystarczająco produktów na magazynie {0} ", dodaj.zestaw.ProduktName5);
                    return(RedirectToAction("Zestaw"));
                }
                else
                {
                    var z = dodaj.product.Total;
                    product5.Total -= dodaj.product.Total;
                    if (product5.Warehouse1 < z)
                    {
                        z -= product1.Warehouse1;
                        product5.Warehouse1  = 0;
                        product5.Warehouse2 -= z;
                    }
                    else
                    {
                        product5.Warehouse1 -= z;
                    }
                    rozchodwewnetrzny.CenaCalkowita += product5.Price * dodaj.product.Total;
                    rozchodwewnetrzny.Produkty      += product5.Name + "\t" + product5.Price + "\n";
                    product.Description             += product5.Name + ",";
                }
            }

            przychodwewmetrzny.CenaCalkowita = rozchodwewnetrzny.CenaCalkowita;
            product.Price = rozchodwewnetrzny.CenaCalkowita / dodaj.product.Total;
            zestaw.Cena   = product.Price;

            repository.SaveProduct(product);
            repository.SaveProduct(product1);
            repository.SaveProduct(product2);
            repository.SaveProduct(product3);
            repository.SaveProduct(product4);
            repository.SaveProduct(product5);

            zestaw.ProductID = product.ProductID;
            repository8.SavePW(przychodwewmetrzny);
            repository10.SaveRW(rozchodwewnetrzny);
            repository6.SaveSet(zestaw);


            TempData["message"] = string.Format("Zapisano {0} ", dodaj.product.Name);
            return(RedirectToAction("Zestaw"));
        }
Esempio n. 29
0
 private void btReadAll_Click(object sender, System.EventArgs e)
 {
     m_direction = RW.READ_ALL;
     btClick(sender, e);
 }
Esempio n. 30
0
 public Channel(RW rw1, RW rw2)
 {
     Terminal1 = new ChannelTerminal(rw1, rw2);
     Terminal2 = new ChannelTerminal(rw2, rw1);
 }
Esempio n. 31
0
 public ConstantRWRef(RW rw)
 {
     this.RW = rw;
 }
Esempio n. 32
0
 public ChannelTerminal(RW write, RW read)
 {
     this.write = write;
     this.read = read;
 }
Esempio n. 33
0
        private void btn_createSalesReport_Click(object sender, EventArgs e)
        {
            RW rw = new RW();

            rw.CreateSalesReport();
        }